0

I'm trying to send some values to the view (layout + partials) using this code (all of these variables have 1 as value).

$this->layout()->setVariables(array(
    'nbTotalLignes'     => $nbTotalLignes,
    'nbTotalPages'      => $nbTotalPages,
    'comptes'           => $comptes,
    'numPageCourante'   => $numPageCourante,
    'nbComptesAffiches' => $nbComptesAffiches,
    'comptesAffiches'   => $comptesAffiches,
));

But when I try to display these in the view using this code echo (isset($this->nbTotalLignes)?1:0, I get 0. How do I please to fix that ?

user3821280
  • 39
  • 1
  • 7

1 Answers1

1

each view has its own scope. $this->layout()->setVariables set the variables for the layout and not your current actions view.

to send vars to the current actions view you have 2 options :

return array('var1'=>1);

zend will automatically convert this to a viewmodel. or

$view = new ViewModel();
$view->setVariables(array('var1'=>1))
return $view;

with this approach you can also set a different template

$view->setTemplate('a different template path'); 

and choose not to render layout

$view->setTerminal(true)
Exlord
  • 5,009
  • 4
  • 31
  • 51
  • what's a template ? a view which doesn't use the default layout ? – user3821280 Jul 10 '14 at 07:31
  • layout is shared between all actions(pages) and is the structure of the page, but each action has its own view layout called template with is the output of that action witch is added to the main layout – Exlord Jul 11 '14 at 08:23