Mr Rost Mr Rost - 1 month ago 9
PHP Question

How put some variable in Nav widget

I did links from

Html::a
and get them parameter
type
, and now I want to put this links to header and I'm trying to change main layout. I put link like that:

['label' => 'USA', 'url' => ['index.php/rates'], 'type' => ['USA']],


but it doesn't work. How can I do this in layout?

I put parameter in action in my Controller like that:

public function actionIndex($type = 'USA')
{
}

Answer

I do this way

    ['label' => 'USA', 
          'url' => ['index.php/rates?type=USA]],

or for vars

   ['label' => 'USA', 
          'url' => ['index.php/rates?type='. $my_var]],

If you need to pass parameter form a controller/action to a view or a layout

you can use

  use Yii;

  Yii::$app->view->params['your_param'] = 'your_value';

then in controller/action you can assign a value to a param this way :

  public function actionYourAction()
  {
    .........
    $this->view->params['your_param'] = 'your_value';

Then in your layout you can

  echo $this->params['your_param'];