I
I
Ilya Lesnykh2011-10-20 14:44:14
Zend Framework
Ilya Lesnykh, 2011-10-20 14:44:14

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

6 answer(s)
I
Ilya Lesnykh, 2011-10-21
@Aliance

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

S
SeriousDron, 2011-10-20
@SeriousDron

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;

A
Anatoly, 2011-10-20
@taliban

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 =)

S
sergeyvolobuev, 2011-10-20
@sergeyvolobuev

somewhere in MVC:
Zend\Layout\Layout::getMvcInstance()->varName = "Title"
In layout:
echo $this->varName;

A
Artem Bondarenko, 2011-10-21
@mr_avi

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 question

Ask a Question

731 491 924 answers to any question