Created
January 29, 2013 13:30
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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