1

I have created two layouts: one for the login page and another for the rest of the site. After login I want to pass variables from login controller to zf2 layout, but not able to access.

How can i access the variables in layout created in a controller action?

Cœur
  • 37,241
  • 25
  • 195
  • 267
anupkumar
  • 357
  • 4
  • 14
  • 28

1 Answers1

6

Some ways to do that in your controller:

Using view model

$viewmodel = new ViewModel();
$viewmodel->setVariable('myvar', $myvar);
return $viewmodel;

Using layout()

$this->layout()->myvar = $myvar;

Into your view script

<?php echo $this->myvar; ?>
Remi Thomas
  • 1,528
  • 1
  • 15
  • 25