Magento - 注册表和当前类别

时间:2012-04-23 14:49:26

标签: session magento magento-1.4 magento-1.5

我对Mage::registrycategories:有关于类别页面的问题,我按Mage::registry('current_category')检索当前类别。我注意到它只适用于根类别,事实上,如果我访问子类别页面,我总是使用Mage::registry('current_category')检索根类别。所以问题是:关于后端配置,缓存还是别的东西?

3 个答案:

答案 0 :(得分:7)

如果您在模板中(例如catalog/category/view.phtml),则可以使用

获取当前类别
$this->getCurrentCategory();

如果您在模特,控制器或其他人中,请尝试此操作(找到here):

Mage::getModel('catalog/layer')->getCurrentCategory();

但是,Mage::registry('current_category')是正常的方式。

答案 1 :(得分:4)

OOB,current_category设置在Mage_Catalog CategoryController::_initCategory()(参考here)中,并且始终等于当前正在查看的类别。

如果您的数据不同,那么您的应用具有非标准功能,或者您看到缓存结果。

答案 2 :(得分:1)

对于所有类别: -

<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>

目前的类别

<?php $currentCategory = Mage::registry('current_category') ?>

适合我。

相关问题