2012-08-16 81 views
0

希望大家都做得很好。我是magento的新手。我正在研究magento模块。我想在管理中使用网格,但我需要使用集合。我创建了一些集合,并且没有成功地访问它们中的任何一个。我想知道我错在哪里。让我与你分享我的问题。magento:创建您自己的收藏

我的配置文件块

<models> 

    <exporter> 
     <class>World_Exporter_Model</class> 
     <!-- 
     need to create our own resource, cant just 
     use core_mysql4 
     --> 
     <resourceModel>exporter_mysql4</resourceModel> 
    </exporter> 
<exporter_mysql4> 
     <class>World_Exporter_Model_Mysql4</class> 
     <entities> 
      <exporter> 
         <table>profiles</table> 
      </exporter> 
     </entities> 

</exporter_mysql4> 
</models> 

我的模型

class World_Exporter_Model_Mysql4_Profiles extends Mage_Core_Model_Mysql4_Abstract 
{ 
public function _construct() 
{ 

    $this->_init('exporter/profiles', 'profile_id'); 
} 
} 

我的收藏

class World_Exporter_Model_Mysql4_Profiles_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract 
{ 
public function _construct(){ 
    parent::_construct(); 
    $this->_init('exporter/profiles'); 
} 
} 

如果你想帮助我。我很满。

(由得到回答后)....

$model = Mage::getResourceModel('exporter/profiles'); 

    // $model = Mage::getModel('exporter/profiles');   

    $collection = $model->getCollection();   

致命错误:调用未定义方法World_Exporter_Model_Mysql4_Profiles :: getCollection()

// $model = Mage::getResourceModel('exporter/profiles'); 

     $model = Mage::getModel('exporter/profiles');   

     $collection = $model->getCollection(); 

一个:5:{I:0; s:47:Can not retrieve entity config:exporter/profiles“; i:1; s:2542:

#0 \ app \ code \ core \ Mage \ Core \ Model \ Resource.php(272):法师:: throwException('无法检索...')

#1 \应用\代码\核心\法师\核心\型号\资源\ DB \ Abstract.php(284):Mage_Core_Model_Resource-> getTableName时( '出口/ PROFIL ...')

#2 \程序\代码\核心\法师\核心\型号\资源\ DB \ Abstract.php(247):Mage_Core_Model_Resource_Db_Abstract-> getTable( '曲线')

但我有在DB

表 “谱”

我会感谢您的帮助...

回答

4

所以最后由我自己得到的答案,因为我没有得到足够的回应,所以我必须自己去做,非常感谢我的问题的唯一回应者,实际上他的回答帮助我解决了这个问题,所以也得到了信任。

现在的解决方案

<exporter> 
    <class>World_Exporter_Model</class> 

    <resourceModel>exporter_mysql4</resourceModel> 
</exporter> 
<exporter_mysql4> 
    <class>World_Exporter_Model_Mysql4</class> 
    <entities> 
     <!-- This portion makes it stop working --> 
     <exporter> 
        <table>profiles</table> 
     </exporter> 
     <!-- This portion makes it stop working --> 

     <!-- Replace the above highlighted portion with this portion --> 
     <profiles> 
        <table>profiles</table> 
     </profiles> 

     <!-- Replace the above highlighted portion with this portion --> 

    </entities> 

</exporter_mysql4> 
</models> 

所以在上面的代码(XML),我们更换了配置文件

,然后编写代码

class World_Exporter_Model_Profiles extends Mage_Core_Model_Abstract 
{ 
    public function _construct() 
    { 
     // now profiles in this will catch the table name within profiles tags 
     $this->_init('exporter/profiles'); 
    } 
} 

出口标签它开始为我工作。

1

看起来你错过了模型。如果你在你的config xml中查看,你调用你的模型是你的资源模型。您仍然需要定义实际模型。同样,在你的配置XML,这种模式已经被声明:<class>World_Exporter_Model</class>

基本类应该是这样的:

class World_Exporter_Model_Profiles extends Mage_Core_Model_Abstract 
{ 
    public function _construct() 
    { 

     $this->_init('exporter/profiles'); 
    } 
} 

,并应在/app/code/local/World/Exporter/Model/Profiles.php

+0

对于迟到的回复,我很抱歉,因为我是在度假。无论如何,我非常感谢您提供的帮助。但我认为我们错过了一些东西。我在问题中添加了这个问题,由于字符限制,我无法在这里发帖。请帮我通过它,如果我要求一些明显的PLZ不介意它,因为我是新的magento .. – fkabeer 2012-08-23 07:38:31