我正在使用一個模塊,它調用塊中的一個函數,並且在該塊內部,我嘗試使用Mage::registry('current_category')
來提取當前類別。但是它總是返回NULL。我試過從產品頁面,搜索頁面這樣做 - 仍然沒有。有沒有任何理由,它會返回NULL,我可以檢查什麼是一些東西?爲什麼Mage :: registry('current_category')會返回NULL的任何原因?
回答
很空,因爲它未設置。註冊表充當全局變量的系統,不依賴PHP內置的全局支持。不能保證任何已經註冊的變量都可以在每個頁面上使用。例如,你說過你在搜索頁面上試過這個。 current_category
應該在搜索頁面上?
它是空的,因爲它應該是。其中,這是設置
此外,只有在URL中包含相關類別名稱的情況下,纔會爲產品頁面設置類別 – clockworkgeek 2011-06-07 16:01:05
我認爲這很有道理:)謝謝 – 2011-06-08 13:33:32
@clockworkgeek但在我的情況下,在poduct頁面上一些公關oducts(所有在URL中沒有類別名稱)'Mage :: registry('current_category')'返回null,但在其他情況下它返回類別對象。這是爲什麼? – KoviNET 2014-02-27 21:03:37
試試這個:
$category = $this->helper('catalog/category')->getCategoryUrl(Mage::registry('current_category'));
:('致命錯誤:調用一個非對象的成員函數的getData()在... \ Magento的\程序\代碼\ core \ Mage \ Catalog \ Helper \ Category.php on line ' – 2011-06-07 12:17:46
...並且您的模板文件是? – 2011-06-07 12:47:12
如果Mage :: registry('current_category')的返回值爲null,則獲取 – 2015-02-10 21:27:04
- 1. Chrome爲什麼會爲sessionID返回null?
- 2. 爲什麼CreatePointFont()會爲我返回NULL?
- 3. 爲什麼我的ClaimsRequest會返回null?
- 4. 任何想法爲什麼這些默認值會返回null?
- 5. 爲什麼我的方法不會返回任何東西,而是返回null?
- 6. 爲什麼任務沒有返回null
- 7. File.getAbsolutePath()返回null的可能原因是什麼?
- 8. 爲什麼Throwable.getMessage()偶爾會返回null?
- 9. 爲什麼會這樣返回NULL
- 10. 爲什麼TextToSpeech.getLanguage()*有時*會返回null?
- 11. 爲什麼它會一直返回「null」?
- 12. 爲什麼curl會返回null?
- 13. presentShareDialog返回nil的原因是什麼?
- 14. BufferedReader返回Null無明顯原因
- 15. 爲什麼parseJSON返回null
- 16. 爲什麼Geocoder.getFromLocationName返回null?
- 17. 爲什麼Type.GetElementType返回null?
- 18. 爲什麼getActionView()返回null
- 19. 爲什麼documentUrl返回NULL
- 20. 爲什麼beanContainer.getBeanByName(...)返回null?
- 21. 爲什麼stringForKey返回null?
- 22. getPerson()返回NULL,爲什麼?
- 23. 爲什麼BitmapFactory.decodeFile返回null?
- 24. 爲什麼PsGetCurrentProcessId()返回null?
- 25. 爲什麼SCOPE_IDENTITY返回NULL?
- 26. 爲什麼RedirectToAction返回null?
- 27. 爲什麼Images.Media.insertImage返回null
- 28. 爲什麼findViewById(...)返回null?
- 29. 爲什麼getProperty()返回null?
- 30. 爲什麼SelectSingleNode返回null?
你可以用調試器chekc和它得到取消設置 – 2011-06-07 11:53:11