久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Magento getSingleton() 與 getModel() 問題

Magento getSingleton() vs getModel() issue(Magento getSingleton() 與 getModel() 問題)
本文介紹了Magento getSingleton() 與 getModel() 問題的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想在 Magento 中遍歷一系列產品 ID.在循環中,我將產品的一些自定義屬性顯示為:

I want to loop over an array of product IDs in Magento. In the loop I am displaying some custom attributes of the products as:

foreach ($products as $product) {
   $model = Mage::getSingleton('catalog/product')->load($product['id']);
   echo '<br>' . $model->getCredits();
}

問題是,如果第一項的 getCredits() 值為 true,那么所有后續項都顯示 true,即使它們沒有值 true.

Problem is that if the value of getCredits() for the first item is true then all the subsequent items show true even if they do not have the value true.

但是當我使用 Mage::getModel() 而不是 Mage::getSingleton() 時,屬性值顯示正確.

But when I use Mage::getModel() instead of Mage::getSingleton(), the attribute values are displayed correct.

誰能解釋一下這個區別?

Can anyone please explain this difference?

推薦答案

Mage::getModel() 將始終為給定模型返回一個新對象:

Mage::getModel() will always return a new Object for the given model:

/**
 * Retrieve model object
 *
 * @link    Mage_Core_Model_Config::getModelInstance
 * @param   string $modelClass
 * @param   array|object $arguments
 * @return  Mage_Core_Model_Abstract|false
 */
public static function getModel($modelClass = '', $arguments = array())
{
    return self::getConfig()->getModelInstance($modelClass, $arguments);
}

Mage::getSingleton() 將檢查給定模型的對象是否已經存在,如果存在則返回.如果它不存在,它將創建一個給定模型的新對象,并將其放入已存在的注冊表中.下一次調用不會返回新對象,而是返回現有對象:

Mage::getSingleton() will check whether the Object of the given model already exists and return that if it does. If it doesn't exist, it will create a new object of the given model and put in registry that it already exists. Next call will not return a new object but the existing one:

/**
 * Retrieve model object singleton
 *
 * @param   string $modelClass
 * @param   array $arguments
 * @return  Mage_Core_Model_Abstract
 */
public static function getSingleton($modelClass='', array $arguments=array())
{
    $registryKey = '_singleton/'.$modelClass;
    if (!self::registry($registryKey)) {
        self::register($registryKey, self::getModel($modelClass, $arguments));
    }
    return self::registry($registryKey);
}

在您的情況下,您總是想要一個全新的 Product 對象/模型,因為每個產品都是獨一無二的...

In your case you always want a completely new Product object/model since every product is unique...

這篇關于Magento getSingleton() 與 getModel() 問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 成人免费视频网站在线看 | 国产精品久久久久久久久免费樱桃 | 国产成人精品a视频一区www | 亚洲色欲色欲www | 免费艹逼视频 | 免费啪啪| 涩涩片影院 | 国产一区二区三区四区 | 伊人成人免费视频 | 久久精品国产v日韩v亚洲 | 日韩在线小视频 | aaaaaa大片免费看最大的 | 亚洲www啪成人一区二区 | 久久一起草| 精品一区二区久久久久久久网精 | 一级黄色片日本 | 精彩视频一区二区三区 | av影音资源 | 欧美日韩在线一区二区三区 | 91精品国产综合久久久久久 | 午夜性色a√在线视频观看9 | 色橹橹欧美在线观看视频高清 | 精品9999| 羞羞视频在线观免费观看 | 夜夜夜夜夜夜曰天天天 | 福利视频一区二区三区 | 我要看免费一级毛片 | 国产黄色大片在线观看 | 精品欧美视频 | 国产精品久久久久久久久久尿 | 看片国产| 欧美日韩淫片 | 国产免国产免费 | 一区二区三区小视频 | 国产一级电影在线观看 | 久久国产婷婷国产香蕉 | 久久这里有精品 | 亚洲欧美视频一区 | 伊人色综合久久天天五月婷 | av福利网站 | 99pao成人国产永久免费视频 |