Module.php 1.31 KB
Newer Older
Bertrand Gauthier's avatar
Bertrand Gauthier committed
1
2
3
4
5
6
<?php

namespace Application;

use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
7
use Zend\Http\Request as HttpRequest;
Bertrand Gauthier's avatar
Bertrand Gauthier committed
8
9
10
11
12
13
14
15
16

class Module
{
    public function onBootstrap(MvcEvent $e)
    {
        $e->getApplication()->getServiceManager()->get('translator');
        $eventManager        = $e->getApplication()->getEventManager();
        $moduleRouteListener = new ModuleRouteListener();
        $moduleRouteListener->attach($eventManager);
17
18
19
20
21
22
23
24
25
26

        /* Active un layout spécial si la requête est de type AJAX. Valable pour TOUS les modules de l'application. */
        $eventManager->getSharedManager()->attach('Zend\Mvc\Controller\AbstractActionController', 'dispatch',
            function (MvcEvent $e) {
                $request = $e->getRequest();
                if ($request instanceof HttpRequest && $request->isXmlHttpRequest()) {
                    $e->getTarget()->layout('layout/ajax.phtml');
                }
            }
        );
Bertrand Gauthier's avatar
Bertrand Gauthier committed
27
28
29
30
31
32
33
34
35
    }

    public function getConfig()
    {
        return include __DIR__ . '/config/module.config.php';
    }

    public function getAutoloaderConfig()
    {
36
37
38
        return [
            'Zend\Loader\StandardAutoloader' => [
                'namespaces' => [
Bertrand Gauthier's avatar
Bertrand Gauthier committed
39
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
40
41
42
                ],
            ],
        ];
Bertrand Gauthier's avatar
Bertrand Gauthier committed
43
44
    }
}