Answer the question
In order to leave comments, you need to log in
ZF2 layout variable
Has anyone already sawed ZF2? The task is to pass the variable to the layout inside the controller. How to do it?
It is necessary to transfer the page title (h1, but title), which is located not in the view, but in the general template.
Variables passed to the view from the controller are not seen by the layout.
Answer the question
In order to leave comments, you need to log in
As I was answered here , you need to work through the Application\View\Listener events:
*Controller.php
layout.phtml
$e = $this->getEvent();
$e->setParam('footer', 'test');
<?php print $this->raw('footer'); ?>
I didn’t download it, I looked through the repository view. It seems that the layout helper remains, so as in the first $this->view->layout()->variable = value;
In any case, the layout is also rendered through the view, there’s no other way, I advise you to delve into the code, and more specifically into the relationship between the controller and the layout, it’s useful to do =)
somewhere in MVC:
Zend\Layout\Layout::getMvcInstance()->varName = "Title"
In layout:
echo $this->varName;
The first one had such a dump as Zend_Registry, I can assume that there is Zend\Registry. Thus:
Zend\Registry::set('key', 'value');
<?php echo Zend\Registry::get('key') ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question