2012-07-13 57 views
8

Fatal error: Call to undefined method Desbest_Showdown_Model_Mysql4_Votes_Collection::addAttributeToSelect() in /home/desbest/public_html/clients/magentofull/app/code/local/Desbest/Showdown/controllers/IndexController.php on line 19收藏:: addAttributeToSelect()在Magento未定义的方法

IndexController.php

public function voteAction(){ 
    $shake = Mage::getModel('showdown/votes') 
     ->getCollection() 
     ->addAttributeToSelect('*') 
     ; 
} 

===============

code/local/Desbest/Showdown/Model/Mysql4/Votes/Collection.php

<?php 
class Desbest_Showdown_Model_Mysql4_Votes_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract 
{ 
    public function _construct() 
    { 
     parent::_construct(); 
     $this->_init('showdown/votes'); 
    } 
} 

回答

37

addAttributeToSelect()被使用EAV风格模型集合只(产品,客户等)

对于您可以使用Mage_Core_Model_Resource_Db_Collection_Abstract::addFieldToSelect()方法等车型。

+3

我只需要将'addAttributeToSelect'改成'addFieldToFilter'和'addAttributeToFilter'到'addFieldToFilter'。 – desbest 2012-07-13 21:52:20

1

将此项添加到您的收藏.php

public function addAttributeToSort($attribute, $dir=’asc’) 
{ 
    if (!is_string($attribute)) { 
     return $this; 
    } 
    $this->setOrder($attribute, $dir); 
    return $this; 
} 

您也可以尝试使用addFilter()或使用setOrder()。

资源:This

+0

但我想'addAttributeToSelect'函数。 – desbest 2012-07-13 21:14:29