anupkumar
anupkumar

Reputation: 357

access controller action variables to zf2 layout

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?

Upvotes: 1

Views: 3891

Answers (1)

Remi Thomas
Remi Thomas

Reputation: 1528

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; ?>

Upvotes: 6

Related Questions