カスタム作成されたコレクションにいくつかのアイテムを追加しようとしています。Alan Storm varienデータ収集とこのSOの質問を読んで、私はいくつかの異なるオプションにたどり着きました。
Varien_Data_Collectionを使用する1つのオプションは次のとおりです。
$myResultCollection = new Varien_Data_Collection();
$mybanner = new Varien_Object();
foreach($myBannersCollection as $banner){
$mybanner = $banner;
$search_text = explode(",", $banner->getsearch_text());
foreach ($search_text as $txt){
if (stripos($currentProdName,$txt) !== false) {
$myResultCollection->addItem($mybanner);
}
}
}
このコードは次のエラーをスローします。
Item (Dts_Banners_Model_Bannersadmin) with the same id "10" already exist
そして、現在使用しているモデルのカスタムコレクションを使用した、コードの別のバリエーションを次に示します。
$myResultCollection = Mage::getModel('banners/bannersadmin');
foreach($myBannersCollection as $banner){
$search_text = explode(",", $banner->getsearch_text());
foreach ($search_text as $txt){
if (stripos($currentProdName,$txt) !== false) {
$myResultCollection->addItem($banner);
}
}
}
しかし、これは次のエラーを示しています(すべてを表示していない、長い道のりです):
Invalid method Dts_Banners_Model_Bannersadmin::addItem(Array
(
[0] => Dts_Banners_Model_Bannersadmin Object
(
[_eventPrefix:protected] => core_abstract
[_eventObject:protected] => object
[_resourceName:protected] => banners/bannersadmin
[_resource:protected] =>
[_resourceCollectionName:protected] => banners/bannersadmin_collection
[_cacheTag:protected] =>
[_dataSaveAllowed:protected] => 1
[_isObjectNew:protected] =>
.......
私が間違っているのは何ですか?