0

1つのforeach行のみを表示し、変数を使用することを計画しているため、複数の行の配列をループするために使用したくありません。この情報をオンラインで見つけることができません。

動作しないもの

    $param = $this->getRequest()->getParam('manufacturer');
    $extrabrand = Mage::getModel('brands/brands')->getCollection();
    $extrabrand->addFieldToFilter('attributelabelid', $param);
    //$extrabrand->setAttributelabelid($param);
    $extrabrand->load();

致命的なエラー:20行目の/home/desbest/public_html/clients/magentofull/app/design/frontend/default/default/template/Desbest_Brands/brand_info.phtmlにある未定義のメソッドDesbest_Brands_Model_Mysql4_Brands_Collection :: getDescription()を呼び出します

さらに、EAVはありません。

4

2 に答える 2

11

コードを見ないbrand_info.phtmlと何が問題なのかはわかりませんが、コレクションを$extrabrandモデルのように使用していると思います。代わりにこれを試してください

//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());
于 2012-09-24T18:37:19.067 に答える
2

コレクションから要素を 1 つだけ (最初に) 取得する必要がある場合は、次のcurrent()関数を使用します。

$param = $this->getRequest()->getParam('manufacturer');
$extrabrandCollection = Mage::getModel('brands/brands')->getCollection()
    ->addFieldToFilter('attributelabelid', $param);

$extrabrand = current($extrabrandCollection->getItems());
于 2012-09-24T18:43:31.733 に答える