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

Magento:Mage::registry('current_product') 有效嗎?

Magento: Mage::registry(#39;current_product#39;) efficient?(Magento:Mage::registry(current_product) 有效嗎?)
本文介紹了Magento:Mage::registry('current_product') 有效嗎?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

如果您了解其背后的過程,這可能是顯而易見的.但是,例如,當您在產品頁面上使用 Mage::registry('current_product') 時,您是否只是在引用某些內容已經加載"了還是每次運行該行代碼時都加載它?

This is probably something obvious if you know the process behind it.. But when you use Mage::registry('current_product') on a product page, for example, are you merely referencing something that is already "loaded" or are you loading it every time you run that line of code?

換句話說,哪個更有效率?(下面是偽代碼)

In other words, which is more efficient? (pseudocode below)

Mage::registry('current_product')->getName() over and over

或者...

$temp = Mage::registry('current_product') then
$temp->getName() over and over

推薦答案

調用

Mage::registry('current_product')->getName()

一遍又一遍地稍微

$temp = Mage::registry('current_product') then
$temp->getName() over and over

但這并沒有那么糟糕,我會非常擔心.如果您要設置編碼風格,請選擇第二種.如果你有一堆舊代碼和前者,不要擔心它的性能.

But it's not so bad that I'd be super concerned about. If you're setting a coding style, pick the second. If you have a bunch of old code with the former, don't worry about its performance.

當您調用 Mage::registry('current_product') 時,產品本身不會從數據庫中重新加載 — 此方法所做的只是返回一個存儲在靜態數組中的對象引用Mage 類的.

The product itself won't be reloaded from the database when you call Mage::registry('current_product') —?all this method does is return an object reference that's been stored on a static array of the Mage class.

我說前者效率稍低的原因是,如果你看一下registry

The reason I say the former will be slightly less efficient is, if you take a look at the source of registry

#File: app/Mage.php
public static function registry($key)
{
    if (isset(self::$_registry[$key])) {
        return self::$_registry[$key];
    }
    return null;
}

您將看到 Magento 在返回值之前檢查鍵是否已設置.從理論上講,這項檢查比從 registry 中抓取一次然后重用變量更多的工作.

You'll see Magento check if the key is set before returning a value. This check, theoretically, is more work that grabbing it from registry once and then reusing the variable.

但是,實際上,在這成為真正的問題之前,您將遇到更大的瓶頸.

However, practically speaking, you're going to have bigger bottlenecks before this is a real problem.

這篇關于Magento:Mage::registry('current_product') 有效嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)
主站蜘蛛池模板: 91久久精品视频 | 国产午夜精品一区二区三区嫩草 | 久热精品在线观看视频 | 精品国产一区一区二区三亚瑟 | 无码国模国产在线观看 | 日本三级黄视频 | 日本在线观看网址 | 在线观看免费av网 | 久久99精品久久久久 | 日韩成人免费av | 香蕉大人久久国产成人av | 成人一区二区电影 | 婷婷成人在线 | 青青久草| 亚洲成人av | www性色| 国产色黄 | 国产精品久久久久久久久久久久 | 久久精品国产免费 | 男女羞羞视频在线免费观看 | 精品一二三区在线观看 | 成人在线免费网站 | 欧美不卡一区二区三区 | 久久久精品影院 | 日韩一二区在线 | 久久久久久久一区二区三区 | 国产美女视频 | 国产精品精品 | 国产精品一区二区视频 | 亚洲综合二区 | 久久精品91 | 五月花丁香婷婷 | 欧美日韩一区二区三区在线观看 | 无码日韩精品一区二区免费 | 亚洲乱码国产乱码精品精98午夜 | 一级做受毛片免费大片 | 国产欧美综合在线 | 久久亚洲欧美日韩精品专区 | 99reav| 一区二区三区观看视频 | 在线中文视频 |