Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Every controller triggers an event <code>dispatch</code> when the controller action is called. This event is encapsuled within an <code>EventManager</code> object which contains some identifiers. This makes it possible for a <code>SharedEventManager</code> to listen to a specific event <strong>within</strong> an EventManager with a specific identifier.</p> <p>Now every controller (eg the <code>MyModule\Controller\FooController</code>) has two known identifiers:</p> <ol> <li>The name of the class (<code>MyModule\Controller\FooController</code>)</li> <li>The top level namespace of the class (<code>MyModule</code>)</li> </ol> <p>The Module.php class for your MyModule is the best place to put this logic. When the application bootstraps, you attach a listener for this module (that is, the namespace of the Module.php class!), for the dispatch event. This makes sure the function is called when your controller's actions are called, but the listener does not execute when another controller is dispatched.</p> <pre><code>namespace MyModule; use Zend\Mvc\MvcEvent; class Module { public function onBootstrap($e) { $app = $e-&gt;getApplication(); $em = $app-&gt;getEventManager(); // Specific event manager from App $sem = $em-&gt;getSharedManager(); // The shared event manager $sem-&gt;attach(__NAMESPACE__, MvcEvent::EVENT_DISPATCH, function($e) { $controller = $e-&gt;getTarget(); // The controller which is dispatched $controller-&gt;layout('layout/my-module-layout'); }); } } </code></pre> <p>This method (how to do stuff with controllers inside a specific module) is also explained at a <a href="http://juriansluiman.nl/en/article/119/attach-a-view-strategy-for-specific-modules" rel="nofollow">blog post of mine</a>. Because module specific layouts become quite a common thing in Zend Framework 2, Evan Coury has made a module for this. It is called <a href="https://github.com/EvanDotPro/EdpModuleLayouts" rel="nofollow">EdpModuleLayout</a> and it's fairly easy when you installed the module.</p> <p>You provide an array of <code>MyModule</code> => <code>layout/template</code> in a configuration and the module handles the rest.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload