Access variable from module's model in view


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


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.

I think that I was wrong expressed. I want to pass global site’s title to layout (value of database column of Setting module).

That’s $title ($this->title, $this->view->title,$title-detail )

For other parameters use $params.

Thanks, I got it work!


$this->title = Yii::t('backend', 'User');

$this->params['breadcrumbsHomeLink'] = ['label' => Yii::t('backend', 'Settings'), 'url' => ['/settings']];

$this->params['breadcrumbs'][] = Yii::t('backend', 'User');



<title><?= Html::encode($this->title) ?></title>




    'homeLink' => isset($this->params['breadcrumbsHomeLink']) ? $this->params['breadcrumbsHomeLink'] : [],

    'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],