|
Hello all
I have a number of components, which perform operations on all of the generated HTML. For example, one component writes the "generated at" date as a comment to the end of the HTML page. Another one rewrites all <img /> src attributes to point to a CDN etc. Previous to zf2 beta5, I achieved this as follows: namespace Application class Module [..] public function init(ModuleManager $moduleManager) { $sharedManager = $moduleManager->events()->getSharedManager(); $sharedManager->attach('Zend\Mvc\Application', 'finish', array('My\X\GeneratedAt', 'execute'), 2); $sharedManager->attach('Zend\Mvc\Application', 'finish', array('My\X\Cdn', 'execute'), 3); } Where My\X\GeneratedAt and My\X\Cdn perform their operations on the HTML. How can I achieve the same functionality in ZF2 beta5? TIA Jonathan |
|
Hi Jonathan,
that should quite work, try it with the alias 'application' instead of 'Zend\Mvc\Application' Hasan H. Gürsoy (HHGAG) Jonathan Maron <[hidden email]> schrieb: >Hello all > >I have a number of components, which perform operations on all of the >generated HTML. > >For example, one component writes the "generated at" date as a comment >to the end of the HTML page. Another one rewrites all <img /> src >attributes to point to a CDN etc. > >Previous to zf2 beta5, I achieved this as follows: > >namespace Application > >class Module [..] > >public function init(ModuleManager $moduleManager) >{ > $sharedManager = $moduleManager->events()->getSharedManager(); > > $sharedManager->attach('Zend\Mvc\Application', 'finish', > array('My\X\GeneratedAt', 'execute'), 2); > > $sharedManager->attach('Zend\Mvc\Application', 'finish', > array('My\X\Cdn', 'execute'), 3); >} > >Where My\X\GeneratedAt and My\X\Cdn perform their operations on the HTML. > >How can I achieve the same functionality in ZF2 beta5? > >TIA > >Jonathan
Hasan H. Gürsoy (HHGAG)
|
|
Hello Hasan
Thanks for your assistance. It turns out, the solution is as follows. How this helps someone: public function onBootstrap(\Zend\Mvc\MvcEvent $e) { $sharedManager = $e->getApplication()->getEventManager()->getSharedManager(); $sharedManager->attach('Zend\Mvc\Application', 'finish', array('My\X\GeneratedAt', 'execute'), 2); $sharedManager->attach('Zend\Mvc\Application', 'finish', array('My\X\Cdn', 'execute'), 3); } Jonathan On Tue, Jul 10, 2012 at 11:21 AM, Hasan H. Gürsoy <[hidden email]> wrote: > Hi Jonathan, > > that should quite work, try it with the alias 'application' instead of 'Zend\Mvc\Application' > > Hasan H. Gürsoy (HHGAG) > > Jonathan Maron <[hidden email]> schrieb: > >>Hello all >> >>I have a number of components, which perform operations on all of the >>generated HTML. >> >>For example, one component writes the "generated at" date as a comment >>to the end of the HTML page. Another one rewrites all <img /> src >>attributes to point to a CDN etc. >> >>Previous to zf2 beta5, I achieved this as follows: >> >>namespace Application >> >>class Module [..] >> >>public function init(ModuleManager $moduleManager) >>{ >> $sharedManager = $moduleManager->events()->getSharedManager(); >> >> $sharedManager->attach('Zend\Mvc\Application', 'finish', >> array('My\X\GeneratedAt', 'execute'), 2); >> >> $sharedManager->attach('Zend\Mvc\Application', 'finish', >> array('My\X\Cdn', 'execute'), 3); >>} >> >>Where My\X\GeneratedAt and My\X\Cdn perform their operations on the HTML. >> >>How can I achieve the same functionality in ZF2 beta5? >> >>TIA >> >>Jonathan |
|
In reply to this post by Jonathan Maron
Hi Jonathan,
my fault, your first one will also work with getEventManager() instead of events() I've overseen that. But onBootstrap is ok in this case Hasan H. Gürsoy (HHGAG) Jonathan Maron <[hidden email]> schrieb: >Hello Hasan > >Thanks for your assistance. It turns out, the solution is as follows. >How this helps someone: > >public function onBootstrap(\Zend\Mvc\MvcEvent $e) >{ > $sharedManager = >$e->getApplication()->getEventManager()->getSharedManager(); > > $sharedManager->attach('Zend\Mvc\Application', 'finish', > array('My\X\GeneratedAt', 'execute'), 2); > > $sharedManager->attach('Zend\Mvc\Application', 'finish', > array('My\X\Cdn', 'execute'), 3); > >} > >Jonathan > >On Tue, Jul 10, 2012 at 11:21 AM, Hasan H. Gürsoy ><[hidden email]> wrote: >> Hi Jonathan, >> >> that should quite work, try it with the alias 'application' instead of 'Zend\Mvc\Application' >> >> Hasan H. Gürsoy (HHGAG) >> >> Jonathan Maron <[hidden email]> schrieb: >> >>>Hello all >>> >>>I have a number of components, which perform operations on all of the >>>generated HTML. >>> >>>For example, one component writes the "generated at" date as a comment >>>to the end of the HTML page. Another one rewrites all <img /> src >>>attributes to point to a CDN etc. >>> >>>Previous to zf2 beta5, I achieved this as follows: >>> >>>namespace Application >>> >>>class Module [..] >>> >>>public function init(ModuleManager $moduleManager) >>>{ >>> $sharedManager = $moduleManager->events()->getSharedManager(); >>> >>> $sharedManager->attach('Zend\Mvc\Application', 'finish', >>> array('My\X\GeneratedAt', 'execute'), 2); >>> >>> $sharedManager->attach('Zend\Mvc\Application', 'finish', >>> array('My\X\Cdn', 'execute'), 3); >>>} >>> >>>Where My\X\GeneratedAt and My\X\Cdn perform their operations on the HTML. >>> >>>How can I achieve the same functionality in ZF2 beta5? >>> >>>TIA >>> >>>Jonathan
Hasan H. Gürsoy (HHGAG)
|
|
Administrator
|
In reply to this post by Jonathan Maron
-- Jonathan Maron <[hidden email]> wrote
(on Tuesday, 10 July 2012, 12:40 PM +0200): > Thanks for your assistance. It turns out, the solution is as follows. > How this helps someone: > > public function onBootstrap(\Zend\Mvc\MvcEvent $e) > { > $sharedManager = > $e->getApplication()->getEventManager()->getSharedManager(); > > $sharedManager->attach('Zend\Mvc\Application', 'finish', > array('My\X\GeneratedAt', 'execute'), 2); > > $sharedManager->attach('Zend\Mvc\Application', 'finish', > array('My\X\Cdn', 'execute'), 3); > > } By the way, there's actually no reason to use the shared event manager in this instance. Since you're grabbing the EM from the application instance already, just register directly with it. public function onBootstrap(\Zend\Mvc\MvcEvent $e) { $events = $e->getApplication()->getEventManager(); $events->attach('finish', array('My\X\GeneratedAt', 'execute'), 2); $events->attach('finish', array('My\X\Cdn', 'execute'), 3); } > On Tue, Jul 10, 2012 at 11:21 AM, Hasan H. Gürsoy > <[hidden email]> wrote: > > Hi Jonathan, > > > > that should quite work, try it with the alias 'application' instead of 'Zend\Mvc\Application' > > > > Hasan H. Gürsoy (HHGAG) > > > > Jonathan Maron <[hidden email]> schrieb: > > > >>Hello all > >> > >>I have a number of components, which perform operations on all of the > >>generated HTML. > >> > >>For example, one component writes the "generated at" date as a comment > >>to the end of the HTML page. Another one rewrites all <img /> src > >>attributes to point to a CDN etc. > >> > >>Previous to zf2 beta5, I achieved this as follows: > >> > >>namespace Application > >> > >>class Module [..] > >> > >>public function init(ModuleManager $moduleManager) > >>{ > >> $sharedManager = $moduleManager->events()->getSharedManager(); > >> > >> $sharedManager->attach('Zend\Mvc\Application', 'finish', > >> array('My\X\GeneratedAt', 'execute'), 2); > >> > >> $sharedManager->attach('Zend\Mvc\Application', 'finish', > >> array('My\X\Cdn', 'execute'), 3); > >>} > >> > >>Where My\X\GeneratedAt and My\X\Cdn perform their operations on the HTML. > >> > >>How can I achieve the same functionality in ZF2 beta5? > >> > >>TIA > >> > >>Jonathan > -- Matthew Weier O'Phinney Project Lead | [hidden email] Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc |
|
> By the way, there's actually no reason to use the shared event manager
> in this instance. Since you're grabbing the EM from the application > instance already, just register directly with it. > > public function onBootstrap(\Zend\Mvc\MvcEvent $e) > { > $events = $e->getApplication()->getEventManager(); > $events->attach('finish', array('My\X\GeneratedAt', 'execute'), 2); > $events->attach('finish', array('My\X\Cdn', 'execute'), 3); > } Thank you Matthew for the suggestion. This does, indeed, make more sense. ;-) Jonathan |
| Powered by Nabble | Edit this page |
