如何在出现异常的情况下正确执行cron作业Mage_Corre_exception,并显示消息“无效的模型/方法定义”



我会尽可能直接切入要点,我使用的是Magento 1.9。我在我的简单cron模块中有以下一段代码,每次执行cron作业时,我都可以看到日程记录良好,但我在消息的日志中看到了以下错误。

异常"Mage_Core _exception",消息为"无效的模型/方法"定义,应为"模型/类::方法"。'在/Users/XXXXX/Sites/projects/php/web/magento/magento_test1.9/SRC/app/Mage.php:595 中

堆栈跟踪:#0/Users/XXXXX/Sites/projects/php/web/magento/magento_test1.9/SRC/app/code/core/Mage/Cron/Model/Observer.php(299):Mage::throwException("无效型号/m…")

#1/Users/XXXXX/Sites/projects/php/web/magento/magento_test1.9/SRC/app/code/core/Mage/Cron/Model/Observer.php(72):Mage_Ron_Model_Observer->_processJob(对象(Mage_Ron_Model_Schedule),对象(Mage_Core _Model_Config_Element))

#2/Users/XXXXX/Sites/projects/php/web/magento/magento_test1.9/SRC/app/code/core/Mage/core/Model/app.php(1358):Mage_Ron_Model_Observer->调度(对象(Varien_Event_Observer))

#3/Users/XXXXX/Sites/projects/php/web/magento/magento_test1.9/SRC/app/code/core/Mage/core/Model/app.php(1337):Mage_Core _ Model_App->_callObserver方法(对象(Mage_Ron_Model_Observer)、"调度"、对象(Varien_Event_Observer

#4/Users/XXXXX/Sites/projects/php/web/magento/magento_test1.9/SRC/app/Mage.php(448):Mage_Core _ Model_App->调度事件("默认",阵列)

#5/Users/XXXXX/Sites/projects/php/web/magento/magento_test1.9/SRC/test_cron.php(76):Mage::dispatchEvent("默认")

#6{main}

我的配置:config.xml

<?xml version="1.0"?>
<config>
    <!-- lets define the module name and version -->
    <modules>
        <Mymodule_Update>
            <version>0.1.0</version>
        </Mymodule_Update>
    </modules>
    <frontend>
            <!-- lets define the module router i.e. for request to any controller within the module and action e.g. mymodule/controller/action -->
        <routers>
            <update>
                <use>standard</use>
                <args>
                    <module>Mymodule_Update</module>
                    <frontName>mymoduleupdate</frontName>
                </args>
            </update>
        </routers>
        <!-- lets define the layout to be used by this module -->
        <layout>
            <updates>
                <update module="Mymodule_Update">
                    <file>mymoduleupdate.xml</file>
                </update>
            </updates>
        </layout>
    </frontend>
    <crontab>
        <jobs>
            <!-- every 5 minute-->
            <mymodule_update_in>
                <schedule>
                    <cron_expr>*/5 * * * * </cron_expr>
                </schedule>
                <run>
                    <model>
                        mymodule_update/updater::performUpdateIn
                    </model>
                </run>
            </mymodule_update_in>
            <!-- every 5 minute-->
            <mymodule_update_out>
                <schedule>
                    <cron_expr>*/5 * * * * </cron_expr>
                </schedule>
                <run>
                    <model>
                        mymodule_update/updater::performUpdateOut
                    </model>
                </run>
            </mymodule_update_out>
        </jobs>
    </crontab>
    <global>
            <!-- lets define the models to use-->
        <models>
            <mymodule_update>
                <resourceModel>mymodule_update_resource</resourceModel>
                <class>Mymodule_Update_Model</class>
            </mymodule_update>
            <mymodule_update_resource>
                <class>Mymodule_Update_Model_Resource</class>
            </mymodule_update_resource>
        </models>
        <helpers>
            <mymodule_update>
                <class>Mymodule_Update_Helper</class>
            </mymodule_update>
        </helpers>
        <resources>
            <mymodule_update_setup>
                <setup>
                    <module>Mymodule_Update</module>
                    <class>Mymodule_Update_Model_Resource_Setup</class>
                </setup>
            </mymodule_update_setup>
        </resources>
        <events>
        </events>
    </global>
</config>

我的班级Updater.php:

<?php 
class Mymodule_Update_Model_updater
{
    public function performUpdateIn()
    {
        die("hello in");
    }

    public function performUpdateOut()
    {
        die("hello out");
    }
}
?>

我不知道为什么会发生这种情况,我已经尝试过使用

mymodule_update/updater::performUpdateOut
update/updater::performUpdateOut

mymodule_update/updater::performUpdateIn
update/updater::performUpdateIn

我也犯了同样的错误。我希望任何知道为什么会出错的人都能为我指明正确的方向,谢谢。

发现问题在于执行操作的xml标记之间的间距

                <model>
                    mymodule_update/updater::performUpdateOut
                </model>

应该是

<model>mymodule_update/updater::performUpdateOut</model>

对于performUpdateIn也是如此。

试图美化或允许一些代码编辑器在两者之间添加空格可能会导致数小时不必要的脑力劳动。

最新更新