Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii framework pass variable from controller to view

To pass variable to login view I use:

$this->render('login', array('model' => $model));

But I also need acces this variable in template part footer.php:

I try this:

$this->render('footer', array('model' => $model));

But when in footer.php I try acces variable I get error "undefined variable"

What is wrong ?

like image 435
Wizard Avatar asked Dec 15 '22 19:12

Wizard


1 Answers

You can use controller class to pass variables in view template, for example

Controller :

SomeController extends Controller {
    
    public function actionIndex() {
          $var1 = 'abc';
          $var2 = '123';
           $this->render('view', 
                           array('var1' => $var1,
                                 'var2' => $var2,
                                ));
    }
}

In view template file you can access these 2 variables ( $var1 & $var2) with its name :

echo $var1; 

echo $var2 
like image 69
Manoj Singh Avatar answered Dec 17 '22 09:12

Manoj Singh