magento:创建自己的收藏

时间:2012-08-16 20:36:41

标签: magento collections

希望每个人都做得很好。我是magento的新手。我正在研究magento模块。我想在Admin中使用网格,但我需要使用集合。我已经创建了一些集合,并且没有成功访问它们中的任何一个。我想知道我错在哪里。让我与你分享我的问题。

我的配置文件块

<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();

a:5:{i:0; s:47:无法检索实体配置:exporter / profiles“; i:1; s:2542:

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

#1 \ app \ code \ core \ Mage \ Core \ Model \ Resource \ Db \ Abstract.php(284):Mage_Core_Model_Resource-&gt; getTableName('exporter / profil ...')

#2 \ app \ code \ core \ Mage \ Core \ Model \ Resource \ Db \ Abstract.php(247):Mage_Core_Model_Resource_Db_Abstract-&gt; getTable('profiles')

但我确实在db

中有表“profiles”

我将感激你的帮助......

2 个答案:

答案 0 :(得分: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 :(得分:1)

看起来你错过了模特。如果您查看配置xml,您所谓的模型就是您的资源模型。您仍然需要定义实际模型。同样,在您的config 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

相关问题