2

我创建了一个自定义模块。失败的电话是:

$collection = Mage::getModel('[modulename]/[model]')->getCollection(); 
$collection->addFieldToFilter('is_public', 1)->getSelect();
$collection = Mage::getModel('[modulename]/[model]')->getCollection()->getFirstItem();//

显然,我在模型中搞砸了一些东西。他们来了:

型号/[型号].php

class [namespace]_[modulename]_Model_[model] extends Mage_Core_Model_Abstract {
     public function _construct() {
         parent::_construct();
         $this->_init('[modulename]/[model]');
     }   
}

型号/Mysql4/[型号].php

class [namespace]_[modulename]_Model_Mysql4_[model] extends Mage_Core_Model_Mysql4_Abstract        {
    public function _construct() {
       $this->_init('[modulename]/[model]', 'id');
     }   
 }

型号/Mysql4/[型号]/Collection.php

class [namespace]_[modulename]_Mysql4_[model]_Collection extends
Mage_Core_Model_Mysql4_Collection_Abstract {
       protected function _construct() {
          //parent::_construct();
          $this->_init('[modulename]/[model]');
       }   
}

收藏作品,有点。

$collection = Mage::getModel('[modulename]/[model]')->getCollection()->getData();

上面的代码返回表中的所有行。一旦我尝试对其应用另一个功能,它就会失败。从我读过的内容来看, addFieldToFilter 应该只适用于正确设置的集合。

这是在magento中。谢谢你的帮助!

4

1 回答 1

0

Check the following:

  1. What is the class of your Object in question and check if this class has getFirstItem() function in place.

Note: abstract class Mage_Core_Model_Resource_Db_Collection_Abstract extends Varien_Data_Collection_Db does not have getFirstItem()

class Varien_Data_Collection implements IteratorAggregate, Countable

has this function.

So check as stated above what is the class of your Object class in question.

Paste your specific code lines where this error is coming from.

于 2013-05-02T03:33:23.833 回答