开发者

How to call a method before the method of requested controller is executed : magento

I want to call a method before the execution of every and each controller's method. I don't want to go and call the method in every method. I just want to c开发者_开发问答all it from one place and it will be called before any method of any controller in magento.

And I am sure we can do this but I don't know how it can be accomplished.

Please provide your suggestions.

Hope we can resolve this or may some expert guys already resolved this.

Thanks.


You need to create an Observer that binds to the controller_action_predispatch Event. That will fire before every controller in the Magento codebase. There's a useful wiki page here that walks you through the process.


You have to create a method called preDispatch in your controller. This method is executed before the requested controller action.

something like:

public function preDispatch()
    {
        parent::preDispatch();

        //my code here
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜