Reputation: 4896
I don't want to use foreach
to loop through an array of multiple rows, as I am planning on only displaying only one row and using a variable. I can't find information for this online.
What doesn't work
$param = $this->getRequest()->getParam('manufacturer');
$extrabrand = Mage::getModel('brands/brands')->getCollection();
$extrabrand->addFieldToFilter('attributelabelid', $param);
//$extrabrand->setAttributelabelid($param);
$extrabrand->load();
Fatal error: Call to undefined method Desbest_Brands_Model_Mysql4_Brands_Collection::getDescription() in /home/desbest/public_html/clients/magentofull/app/design/frontend/default/default/template/Desbest_Brands/brand_info.phtml on line 20
Plus there is no EAV.
Upvotes: 0
Views: 11250
Reputation: 3694
If you need to get only 1 element (first) from the collection, use current()
function:
$param = $this->getRequest()->getParam('manufacturer');
$extrabrandCollection = Mage::getModel('brands/brands')->getCollection()
->addFieldToFilter('attributelabelid', $param);
$extrabrand = current($extrabrandCollection->getItems());
Upvotes: 2
Reputation: 166076
Without seeing the code in brand_info.phtml
it's hard to say what the problem is, but my guess is you're using the collection in $extrabrand
as though it were a model. Try this instead
//get the parameter from the request
$param = $this->getRequest()->getParam('manufacturer');
//instantiate the brand/brand model, and use
//its `getCollection` method to return a collection
//object
$collection = Mage::getModel('brands/brands')->getCollection();
//add the paramater as a filter
$collection->addFieldToFilter('attributelabelid', $param);
//get the first item of the collection (load will be called automatically)
$extrabrand = $collection->getFirstItem();
//look at the data in the first item
var_dump($extrabrand->getData());
Upvotes: 11