Answer the question
In order to leave comments, you need to log in
global variable in yii2?
In general, look. There is a layout, like main. Standard like this. With a category column. These categories are displayed by the widget. Multilevel. Each category has a list of products. The point is. We go to the site, and get a list of some goods, they do not suit, of course, we go to the category to look for the right one. Here. At this time, the processing of category jumps is handled by the CategoryController.php controller, for example. There is also a rule for routing: '<category:\w+>' => 'category/index',
So, we entered some category, the controller was called, the action was called, the incoming parameter, of course, turned out:
public function actionIndex($category = null)
{
//....
}
echo \frontend\widgets\Categories::widget([
'category' => isset(Yii::$app->controller->actionParams['category']) ? Yii::$app->controller->actionParams['category'] : null,
]);
Yii::$app->controller->actionParams['category'] = $model->category->slug;
Answer the question
In order to leave comments, you need to log in
In the controller:
$this->view->params
Right in the view:
$this->params
See how standard breadcrumbs work.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question