开发者

Magento: What is the best way to extend Magento to add a class that is called on every page load

开发者 https://www.devze.com 2022-12-30 02:51 出处:网络
I am looking to create some new functionality to Magento. I am going to be looking to the url and grabbing a paramete开发者_运维百科r. The issue is, this can be on any page. So I can\'t just extend a

I am looking to create some new functionality to Magento. I am going to be looking to the url and grabbing a paramete开发者_运维百科r. The issue is, this can be on any page. So I can't just extend a Catalog or Checkout Module.

I thought about extending the session classes but I wasn't sure it really fit. Basically I want to grab a parameter from the url and from there add some functionality if it is set or not. I don't think a class will get auto loaded unless it is instantiated somewhere else with a getModel method, am I wrong?

How can you add a module that doesn't have a url path for controller and what not, but doesn't fit extending one of the core modules?

I looked for a generic event but didn't really see one like before_page_load or something


Take a look at the event controller_action_predispatch in app/code/core/Mage/Core/Controller/Varien/Action.php. This event should get called on each dispatch and allow you to grab whatever parameters you need.

The event passes the controller as data, so you can do this:

function yourEvent( $event ) {
    $controller = $event->getController();
    // your processing here
}

Let me know if that doesn't fit the bill. Hope that helps!

Thanks, Joe

0

精彩评论

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

关注公众号