what does $this->_coreRegistry->registry('current_category') return
in magento 2 ?
1 Answer
$this->_coreRegistry
is an instance of \Magento\Framework\Registry
(vendor/magento/framework/Registry.php)
register
method in \Magento\Framework\Registry
register a new variable and store it in Registry.
registry
method in \Magento\Framework\Registry
returns the value of a registered
variable in Registry otherwise, it returns null
.
You can search in the Magento core directory (vendor/magento) with the search term: ->register('current_category'
to know which value is set to current_category
.
Finally, you can see $this->_coreRegistry->registry('current_category')
return an instance of \Magento\Catalog\Model\Category
or null
.
So, if you visit a page that contains code register current_category
:
$this->_coreRegistry->register('current_category', $category);
you can get current_category
from Registry:
$this->_coreRegistry->registry('current_category')
-
1