dryeyhe0266 2015-11-16 13:00
浏览 47
已采纳

没有加载模型的magento集合

I want to load a model called Repository in my code. The data is inserted correctly in db by model script, primary key is set to 'repository_id'. However, I am not able to read my data, so I might have a problem but I don't see where. Call :

 $repos = Mage::getModel('Module/repository')->getCollection();
    var_dump($repos); // bool false
    $repos = Mage::getResourceModel('Module/repository_collection');
    var_dump($repos); // bool false

        $repos = Mage::getModel('Module/repository')->getResourceCollection(); // error Mage registry key "_resource_singleton/Module/repository" already exists
        var_dump($repos); 

app/code/local/Company/Module/Model/Mysql4/Resource/Repository/Collection.php

class Company_Module_Model_Resource_Repository_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
    public function _construct()
    {
        $this->_init('Module/repository');
    }

}

app/code/local/Company/Module/Model/Mysql4/Resource/Repository.php

class Company_Module_Model_Resource_Repository extends Mage_Core_Model_Mysql4_Abstract
{
    protected function _construct()
    {
        $this->_init('Module/repository', 'repository_id');
    }

}

app/code/local/Company/Module/Model/Repository.php

class Company_Module_Model_Repository extends Mage_Core_Model_Abstract
{

    public function _construct()
    {
        $this->_init('Module/repository');
    }


}

app/code/local/Company/Module/etc/config.xml

<config>
    <global>
        <models>
            <Module>
                <class>Company_Module_Model</class>
                <resourceModel>company_module_resource</resourceModel>
            </Module>
            <company_module_resource>
                <class>Company_Module_Model_Resource</class>
                <entities>
                    <repository>
                        <table>company_repository</table>
                    </repository>
                </entities>
            </company_module_resource>
        </models>
    </global>
</config> 

Edit : I forgot to mention that i am on magento 1.4, thats why i use mysql4 ressources. Thanks

  • 写回答

1条回答 默认 最新

  • doutong6814 2015-11-16 20:06
    关注

    You forgot Mysql4 in you classes names.
    Config:

            <company_module_resource>
                <class>Company_Module_Model_Mysql4_Resource</class>
                <entities>
                    <repository>
                        <table>company_repository</table>
                    </repository>
                </entities>
            </company_module_resource>
    

    Models:

        Company_Module_Model_Mysql4_Resource_Repository_Collection
        Company_Module_Model_Mysql4_Resource_Repository
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?