Skip to content

Instantly share code, notes, and snippets.

@rlandas
Created January 29, 2013 13:30
Show Gist options
  • Save rlandas/4664243 to your computer and use it in GitHub Desktop.
Save rlandas/4664243 to your computer and use it in GitHub Desktop.
ZF2: I need a universal method to initialize various elements (before action), without duplicating my code in every other controller action. Settings were just an example. Reference: http://zend-framework-community.634137.n4.nabble.com/ZF2-Doing-something-before-calling-the-controller-action-td4656922.html#a4656934
For universal solution you may want to try this one, it will work for all Controllers within single Module:
class Module
{
// Evan's changing layout for specific module only
public function init(ModuleManager $moduleManager) {
$sharedEvents = $moduleManager->getEventManager()->getSharedManager();
$sharedEvents->attach(__NAMESPACE__, 'dispatch', function($e) {
$controller = $e->getTarget();
// do your stuff with controller
}, 100);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment