Magento - Mage::registry inside view
I have a scenario where I need to get the current category name in the layered nav. Obvisouly this views block doesnt have access to the current category name and so I am left with a couple of options the easiest being to use Mage::register('开发者_运维百科current_category') inside the view but this is jarring with me and I know it shouldnt be in there.
The other options seem so over the top for such a simple thing (create an override, create a separate module) that I am considering keeping the register access call inside the view.
Just need some opinions from more experienced magento developers out there.
Thanks
If all you are doing is accessing the variable with Mage::registry
, I think that is safe enough. If you were getting a collection, filtering and manipulating values, then you should consider creating your own Block.
The rationale is (IMHO) - anything that would benefit from being cached should be in a Block. Outputting values is fine in a View.
HTH,
JD
精彩评论