class Product{
public function actionIndex()
{
$productId = isset($_GET['id']) ? $_GET['id'] : null;
//if($productId == null) exit;
$news = ProductModel::findOneByPk($productId);
$view = new \View();
$view->items = $news;
$view->display('default/product.php');
}
}
<?php foreach ($items as $item): ?>//stroka 1
<h3><?php echo $item->name; ?></h3>
<img src="/images/product/<?php echo $item->image; ?>" alt="">
<?php endforeach; ?>
public function actionOne()
{
<b>$id = $_GET['id'];</b> // 21 stroka
$item = NewsModel::findOneByPk($id);
$view = new \View();
$view->assign('item', $item);
$view->display('news/one.php');
}
public static function findOneByPk($id)
{
$class = get_called_class();
$sql = 'SELECT * FROM ' . static::$table . ' WHERE id=:id';
$db = new DB();
$db->setClassName($class);
<b>return $db->query($sql, [':id' => $id])[0];</b> //40 stroka
}
<?php foreach <b>($items as $item)</b>: ?> // 1 stroka
<h1><?php echo $item->title; ?></h1>
<div><?php echo $item->author; ?></div>
<?php endforeach; ?>