I need to get Current page Identifier and current module in Magento.
I used the below code.
Mage::app()->getRequest()->getModuleName() - To get current module.
Mage::getSingleton('cms/page')->getIdentifier() - To get current page
Its working once clear the magento cache otherwise it shows the old page and module.
When we check in home page it gives 'cms' as module and 'home' as page. Now I click the Contact page now also it shows same result.
After clear the cache and check the contact page it shows "cms" as modle and 'contact' as page Identifier.
How to get current page Identifier and module without clear cache every time?
To get current module:
Mage::app()->getFrontController()->getRequest()->getModuleName()
To get current CMS page:
Mage::getSingleton('cms/page')->getIdentifier()
$pageID = Mage::getBlockSingleton('cms/page')->getPage()->getIdentifier();
this will return current cms page identifier.
To get correct identifier and URL of current page:
if (!in_array(Mage::app()->getFrontController()->getAction()->getFullActionName(), array('cms_index_noRoute', 'cms_index_defaultNoRoute'))) {
$Identifier = Mage::app()->getFrontController()->getRequest()->getModuleName();
$currentUrl = Mage::helper('core/url')->getCurrentUrl();
}
$Identifier = strtolower($Identifier);
if($Identifier == 'cms'){
$Identifier = Mage::getSingleton('cms/page')->getIdentifier();
}
echo $Identifier = strtolower($Identifier).'<br>'.$currentUrl;
This is what works for me in many cases. Hope this will help someone.
Most likely you'll need to overwrite the constructor to the block you're wanting, for example: Mage_Catalog_Block_Navigation
So, your _constrct()
protected function _construct()
{
$this->addData(array(
'cache_lifetime' => false,
'cache_tags' => array(Mage_Catalog_Model_Category::CACHE_TAG, Mage_Core_Model_Store_Group::CACHE_TAG),
));
}
Should just be:
protected function _construct() {}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With