camel
(Filip Havlicek)
1
Hello!
How to access variable defined in model of some Module?
So for example I have module: frontend/modules/UserModule with model: frontend/modules/user/models/User
How to get some variable from frontend/modules/user/models/User in layout: views/layouts/main.php
Thanks.
Bizley
(Bizley)
2
To put something in layout use variable $params shared among view templates (breadcrumbs use it).
To access it from within view use $this->params.
Otherwise use $this->view->params.
If you want to pass some variable just to a view file simply prepare it in controller and call render with array of variables.
camel
(Filip Havlicek)
3
I think that I was wrong expressed. I want to pass global site’s title to layout (value of database column of Setting module).
Bizley
(Bizley)
4
That’s $title ($this->title, $this->view->title, http://www.yiiframework.com/doc-2.0/yii-web-view.html#$title-detail )
For other parameters use $params.
camel
(Filip Havlicek)
5
Thanks, I got it work!
view:
$this->title = Yii::t('backend', 'User');
$this->params['breadcrumbsHomeLink'] = ['label' => Yii::t('backend', 'Settings'), 'url' => ['/settings']];
$this->params['breadcrumbs'][] = Yii::t('backend', 'User');
...
layout:
<title><?= Html::encode($this->title) ?></title>
...
<?=
Breadcrumbs::widget([
'homeLink' => isset($this->params['breadcrumbsHomeLink']) ? $this->params['breadcrumbsHomeLink'] : [],
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
])
?>
...