如何解决magento中的“资源未设置”错误?

rwqw0loc  于 2022-11-12  发布在  其他
关注(0)|答案(1)|浏览(117)

我正在尝试从mysql数据库中获取一条记录,参数为Mage::getModel('amshuhucustomer/groupdomain')->load($id);
它与观察器一起工作,因此不需要config.xml中的前端
但未加载,并显示“未设置资源”
module/etc/config.xml

<global>
    <models>
        <amshuhucustomer>
            <class>Amshuhu_Customer_Model</class>
            <resourceModel>amshuhucustomer_mysql4</resourceModel>
        </amshuhucustomer>
        <amshuhucustomer_mysql4>
            <class>Amshuhu_Customer_Model_Mysql4</class>
            <entities>
                <groupdomain>
                    <table>customergroupdomain</table>
                </groupdomain>
            </entities>
        </amshuhucustomer_mysql4>
    </models>
    <resources>
        <amshuhucustomer_setup>
            <setup>
                <module>Amshuhu_Customer</module>
                <class>Amshuhu_Customer_Model_Mysql4_Setup</class>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </amshuhucustomer_setup>
        <amshuhucustomer_write>
            <connection>
                <use>core_write</use>
            </connection>
        </amshuhucustomer_write>
        <amshuhucustomer_read>
            <connection>
                <use>core_read</use>
            </connection>
        </amshuhucustomer_read>
    </resources>
......
</global>

Groupdomain.php

class Amshuhu_Customer_Model_Mysql4_Groupdomain extends Mage_Core_Model_Mysql4_Abstract
{
    protected function _construct()
    {
        $this->_init('amshuhucustomer/groupdomain', 'id');
    }
}
vcirk6k6

vcirk6k61#

终于自己找到了答案。
忘记在模型本身中添加初始化。
在_construct方法中添加以下内容解决了该问题。

$this->_init('amshuhucustomer/groupdomain');

相关问题