5 use Zend\Module\Manager,
6 Zend\EventManager\StaticEventManager,
7 Zend\Module\Consumer\AutoloaderProvider;
9 class Module implements AutoloaderProvider
12 protected $viewListener;
14 public function init(Manager $moduleManager)
16 $events = StaticEventManager::getInstance();
17 $events->attach('bootstrap', 'bootstrap', array($this, 'initializeView'), 100);
20 public function getAutoloaderConfig()
23 'Zend\Loader\ClassMapAutoloader' => array(
24 __DIR__ . '/autoload_classmap.php',
26 'Zend\Loader\StandardAutoloader' => array(
27 'namespaces' => array(
28 __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
34 public function getConfig()
36 return include __DIR__ . '/config/module.config.php';
39 public function initializeView($e)
41 $app = $e->getParam('application');
42 $locator = $app->getLocator();
43 $config = $e->getParam('config');
44 $view = $this->getView($app);
45 $viewListener = $this->getViewListener($view, $config);
46 $app->events()->attachAggregate($viewListener);
47 $events = StaticEventManager::getInstance();
48 $viewListener->registerStaticListeners($events, $locator);
51 protected function getViewListener($view, $config)
53 if ($this->viewListener instanceof View\Listener) {
54 return $this->viewListener;
57 $viewListener = new View\Listener($view, $config->layout);
58 $viewListener->setDisplayExceptionsFlag($config->display_exceptions);
60 $this->viewListener = $viewListener;
64 protected function getView($app)
70 $locator = $app->getLocator();
71 $view = $locator->get('view');
72 $url = $view->plugin('url');
73 $url->setRouter($app->getRouter());
75 $view->plugin('headTitle')->setSeparator(' - ')
76 ->setAutoEscape(false)
77 ->append('ZF2 Skeleton Application');
79 $basePath = $app->getRequest()->detectBaseUrl();
81 $view->plugin('headLink')->appendStylesheet($basePath . 'css/bootstrap.min.css');
83 $html5js = '<script src="' . $basePath . 'js/html5.js"></script>';
84 $view->plugin('placeHolder')->__invoke('html5js')->set($html5js);
85 $favicon = '<link rel="shortcut icon" href="' . $basePath . 'images/favicon.ico">';
86 $view->plugin('placeHolder')->__invoke('favicon')->set($favicon);