Any reason Mage :: registry ('current_category') returns NULL?

I am using a template that calls a function in a block, and inside this block I am trying to pull the current category using Mage::registry('current_category') . However, it always returns NULL. I tried to do this from the product page, the search page is still nothing. Is there a reason it will return NULL that I can check?

+6
source share
2 answers

This value is null because it is not set. The registry acts as a system for global variables that do not rely on PHP built into global support. It is not guaranteed that any particular variable that has been registered will be available on every page. For example, you said you tried this on the search page. What should be the current_category on the search page?

This value is null, as it should be.

+10
source

Try the following:

 $category = $this->helper('catalog/category')->getCategoryUrl(Mage::registry('current_category')); 
-1
source

Source: https://habr.com/ru/post/889949/


All Articles