0

Hello everyone I am a beginner in yii2 , I have to create a form in the footer at the main.php layout section. Default does not pass the model . Could you give me an exemplary of how to pass data in the form ? Thanks so much.

Example of Controller and View.

Saba
  • 115
  • 1
  • 15

1 Answers1

1

For a single controller action a simpel way is use the params .

In you controller action before render your view you should add

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

}

and for accessing in layout you should retrieve using

$model = $this->params['model'];
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
  • ok , this works for single action , and if I would like to for all actions ? – Saba Sep 11 '16 at 15:41
  • You should use event or beforeAction for setting the param ..but is bit mode complex .... anyway is what you have asked... – ScaisEdge Sep 11 '16 at 15:42
  • I think what you are trying to do can be found here: https://stackoverflow.com/questions/29998442/yii2-how-to-pass-the-model-instance-to-the-main-layout – johnsnails Jul 01 '19 at 03:37