Let's say we have a module named Cart and want to redirect users if some condition is met. I want to place a redirect at the module bootstrapping stage, before the application reaches any controller.
So here is the module code:
<?php
namespace Cart;
class Module
{
function onBootstrap() {
if (somethingIsTrue()) {
// redirect
}
}
}
?>
I wanted to use the Url controller plugin, but it seems the controller instance is not available at this stage, at least I don't know how to get it.
Thanks in advance
This should do the necessary work:
Can you try this.
The page isn't redirecting properly on error
Of course it gives you an error because you must attach your listener to an event. In the folllowing example i use SharedManager and i attach the listener to
AbstractActionController
.Of course you can attach your listener to another event. Below is just a working example to show you how it works. For mor info visit http://framework.zend.com/manual/2.1/en/modules/zend.event-manager.event-manager.html.