-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathModule.php
More file actions
46 lines (40 loc) · 1.05 KB
/
Module.php
File metadata and controls
46 lines (40 loc) · 1.05 KB
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
43
44
45
46
<?php
namespace EdpSubLayout;
use Zend\Mvc\Controller\Plugin\AbstractPlugin;
use Zend\Mvc\MvcEvent;
use Zend\View\Model\ViewModel;
class Module extends AbstractPlugin
{
protected $template;
public function __invoke($template)
{
$this->template = $template;
return $this;
}
public function onDispatch(MvcEvent $e)
{
if (!$this->template) {
return;
}
$result = $e->getResult();
$model = $e->getViewModel();
$subLayout = new ViewModel;
$subLayout->setTemplate($this->template);
$subLayout->addChild($result);
$model->addChild($subLayout);
}
public function onBootstrap(MvcEvent $e)
{
$e->getApplication()->getEventManager()->attach(MvcEvent::EVENT_DISPATCH, array($this, 'onDispatch'), -50);
}
public function getConfig()
{
return array(
'controller_plugins' => array(
'services' => array(
'subLayout' => $this,
),
),
);
}
}