Magento:controller_action_predispatch无效

时间:2014-10-03 07:44:42

标签: magento

我正在尝试创建controller_action_predispatch事件:

这是我的Mbyte / Pushnotification / etc / config.xml文件代码

   <events>
            <controller_action_predispatch_mbyte_pushnotification_index_index>
               <observers>
                    <Mbyte_Pushnotification>

                        <class>Mbyte_Pushnotification/Observer</class>
                        <method>indexPreDispatch</method>
                    </Mbyte_Pushnotification>
                </observers>
            </controller_action_predispatch_mbyte_pushnotification_index_index>
    </events>

我的控制器代码:Mbyte / Pushnotification / controllers / IndexController.php文件代码

class Mbyte_Pushnotification_IndexController extends Mage_Core_Controller_Front_Action
{

    public function indexAction()
    {
     Mage::log('Run',null,'log.log');

    }
    }

观察员文件代码:

class Mbyte_Pushnotification_Model_Observer {
              public function indexPreDispatch($observer)
               {    
                 Mage::log('Check',null,'observer.log');

                      }}

controller_action_predispatch无效。 我有什么问题吗?

2 个答案:

答案 0 :(得分:0)

触发的事件应为

controller_action_predispatch_pushnotification_index_index 代替 controller_action_predispatch_mbyte_pushnotification_index_index

如果您没有修改控制器的前端名称(&#34; pushnotification&#34;)。

因此,您必须将config.xml更新为

<events>
        <controller_action_predispatch_pushnotification_index_index>
           <observers>
                <Mbyte_Pushnotification>
                    <class>Mbyte_Pushnotification_Model_Observer</class>
                    <method>indexPreDispatch</method>
                </Mbyte_Pushnotification>
            </observers>
        </controller_action_predispatch_pushnotification_index_index>
</events>

你也可以写

<events>
        <controller_action_predispatch_pushnotification_index_index>
           <observers>
                <Mbyte_Pushnotification>
                    <class>pushnotification/observer</class>
                    <method>indexPreDispatch</method>
                </Mbyte_Pushnotification>
            </observers>
        </controller_action_predispatch_pushnotification_index_index>
</events>

如果您将模块命名为&#34; pushnotification&#34;,我认为。

答案 1 :(得分:0)

根据magento定义事件取决于

controller_action_predispatch_frontName_Controller_Youaction

定义如下:

Mage::dispatchEvent('controller_action_predispatch_' . $this->getFullActionName(),
        array('controller_action' => $this));