0

希望每个人都做得很好。我是 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();

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

#0 \app\code\core\Mage\Core\Model\Resource.php(272): Mage::throwException('Can't retrieve ...')

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

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

但我确实在数据库中有表“配置文件”

感谢您的帮助……</p>

4

2 回答 2

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)中,我们用profiles替换了exporter标签

然后编写代码

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');
    }
}

它开始为我工作。

于 2012-09-06T13:17:23.367 回答
1

看起来您缺少模型。如果您查看配置 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

于 2012-08-16T21:25:46.313 回答