【问题标题】:Can't get <source_model> attribute to work on System.XML in Magento无法获取 <source_model> 属性以在 Magento 中处理 System.XML
【发布时间】:2013-11-06 23:37:28
【问题描述】:

我刚刚完成了我的一种自定义运输方式,它在主要方式中有多种方式。所以我想让“允许的方法”列表显示在管理部分。所以我在我的 system.xml 中得到了下面的块

 <allowed_methods translate="label">
    <label>Allowed Methods</label>
    <frontend_type>multiselect</frontend_type>
    <source_model>mycompany_shipping/carrier_somefolder_definitions_methods</source_model>
    <sort_order>20</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>0</show_in_store>
    <can_be_empty>1</can_be_empty>
 </allowed_methods>

但是 Magento 找不到我的课程,因为它总是在“Mage”而不是“local”中查找,它只是抛出这个错误,

include(Mage/Mycompany/Shipping/Model/Carrier/Somefolder/Definitions/Methods.php): 
failed to open stream: No such file or directory  in /Development/trunk/lib/Varien/Autoload.php on line 93

但我的班级是local/Mycompany/Shipping/Model/Carrier/Somefolder/Definitions/Methods.php,班级名称是Mycompany_Shipping_Model_Carrier_Somefolder_Definitions_Methods

我想可能是我在 config.xml 中遗漏了一些东西,所以这是我的 config.xml

<global>
    <models>
        <mycompshipping>
            <class>Mycompany_Shipping_Model</class>
        </mycompshipping>
    </models>
    <resources>
        <mycompshipping_setup>
            <setup>
                <module>Mycompany_Shipping</module>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </mycompshipping_setup>
    </resources>
</global>
<default>
    <carriers>
        <mycompanyrate>
            <model>Mycompany_Shipping_Model_Carrier_Mycompanyrate</model>
        </mycompanyrate>
    </carriers>
</default>

任何想法为什么 Magento 找不到我的课程?

【问题讨论】:

    标签: php xml magento shipping


    【解决方案1】:

    如果 Magento 将 Mage 预先添加到您的课程中,这几乎总是意味着您的配置有误。

    查看您提供的信息,您的源模型配置为

    mycompany_shipping/carrier_somefolder_definitions_methods
    

    这是mycompany_shipping 的组名和carrier_somefolder_definitions_methods 的类名。这意味着 Magento 将通过调用

    来实例化您的源模型
    Mage::getModel('mycompany_shipping/carrier_somefolder_definitions_methods');
    

    但是,看着你的config.xml

    <models>
        <mycompshipping>
            <class>Mycompany_Shipping_Model</class>
        </mycompshipping>
    </models>
    

    您已将模块配置为“声明”模型组名称mycompshipping。这意味着当您实例化模块的类时,您使用表单

    //instantiates as `Mycompany_Shipping_Model_Carrier_Mycompanyrate`
    Mage::getModel('mycompshipping/carrier_mycompanyrate');
    

    您需要更正 system.xml 以实例化正确的源模型,或更改 config.xml 以公开正确的组名。

    【讨论】:

    • 太棒了!!谢谢艾伦!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-07
    • 2014-08-28
    • 1970-01-01
    相关资源
    最近更新 更多