-
Notifications
You must be signed in to change notification settings - Fork 1
/
listing17.txt
43 lines (34 loc) · 1.21 KB
/
listing17.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace Application\Listener;
use Zend\EventManager\EventInterface;
use Zend\EventManager\EventManagerInterface;
use Zend\EventManager\ListenerAggregateInterface;
use Zend\Mvc\MvcEvent;
use Zend\View\Model\ViewModel;
class ApplicationListener implements ListenerAggregateInterface
{
protected $listeners = array();
public function attach(EventManagerInterface $events)
{
$this->listeners[] = $events->attach(MvcEvent::EVENT_RENDER, array($this, 'renderLayoutSegments'), -100);
}
public function detach(EventManagerInterface $events)
{
foreach ($this->listeners as $index => $listener) {
if ($events->detach($listener)) {
unset($this->listeners[$index]);
}
}
}
public function renderLayoutSegments(EventInterface $e)
{
$viewModel = $e->getViewModel(); /* @var $viewModel ViewModel */
$header = new ViewModel();
$header->setTemplate('layout/header');
$viewModel->addChild($header, 'header');
$footer = new ViewModel();
$footer->setTemplate('layout/footer');
$viewModel->addChild($footer, 'footer');
return $e->getResponse();
}
}