Magento - 注册表和当前类别

Luk*_*uke 0 session magento magento-1.4 magento-1.5

我有一个问题Mage::registry,categories:我是一个类别页面,我检索当前类别Mage::registry('current_category').我注意到它只适用于根类别,事实上如果我访问子类别页面,我总是检索根类别Mage::registry('current_category').所以问题是:关于后端配置,缓存还是其他什么?

Seb*_*biF 7

如果您在模板中(例如catalog/category/view.phtml),您可以获得当前类别

$this->getCurrentCategory();
Run Code Online (Sandbox Code Playgroud)

如果你在模特,控制器或其他,试试这个(在这里找到):

Mage::getModel('catalog/layer')->getCurrentCategory();
Run Code Online (Sandbox Code Playgroud)

但是,这Mage::registry('current_category')是正常的方法.