I created CategoryController.php in the controllers folder, everything seems to be writing norms, I cannot display products from the database, it displays the error "http: //site.loc/category/3"
Here is the code in CategoryController.php
<?php namespace app\controllers; use app\models\Category; use app\models\Product; use Yii; class CategoryController extends AppController { public function actionIndex(){ $hits = Product::find()->where(['hit'=>'1'])->limit(4)->all(); $this->setMeta('yiishoptest'); return $this->render('index', compact('hits')); } public function actionView($id){ $id = Yii::$app->request->get('id'); $products = Product::find()->where(['category_id'=>$id])->all(); $category = Category::findOne($id); $this->setMeta ('yiishoptest | . $category->name, $category->keywords, $category->description,'); return $this->render('view', compact('products', 'category')); } }
and here is the web.php code in the config folder
'urlManager' => [ 'class' => 'yii\web\UrlManager', 'baseUrl' => '//site.loc', 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ 'category/<id:\d+>'=> 'category/view', ],
$this->setMeta
- fedornabilkin