Magento - forward various controller actions from an observer to dispatch

Is it possible to forward another action (within the same controller) based on a certain condition that I can check in the controller's pre-send event?

So, for example, the action to be run has an index index

If I create an observer for a pre-send event, if some condition is true, I would like to trigger another action: myAction, not indexAction

+6
source share
1 answer

You can do something in the following method within before sending.

public function yourMethod($observer) { if ($condition) { $request = Mage::app()->getRequest(); $request->initForward() ->setControllerName('controllername') ->setModuleName('modulename') ->setActionName('actionname') ->setDispatched(false); return false; } } 

Although, if you are working with a custom controller, why not always route it, for example, indexAction ()? And as part of this method, find out where you want to continue (forward), such as Kalpesh mentioned in his answer? Performance is reasonable, there is no difference.

+7
source

Source: https://habr.com/ru/post/921027/


All Articles