Magento: generating url for a backend action (with key)
Solution 1
A secret key should automatically be added to the URL when using
Mage::helper("adminhtml")->getUrl("acompany_mymodule/index/index")
provided that secret keys are enabled in the system config.
Anyway, in this part of your code :
<?php
$key = Mage::getSingleton('adminhtml/url')
->getSecretKey("acompany_mymodule/index/","index");
?>
you give as first parameter a route with a controller, where the method is just waiting for a controller name.
DON'T USE anything else than adminhtml/
as start of the url, because magento 1.9.2.2 forbids everything else.
Solution 2
The other solutions did not work for me as they did not include the Admin Panel base URL (admin by default). I had to do it like this to get the correct URL:
Mage::helper('adminhtml')->getUrl('adminhtml/name_of_custom_extension/name_of_controller/');
Comments
-
Hidalgo almost 2 years
I am working on a demo Magento store (CE v1.7)
I want to generate a link for an action (index) of a controller (index) of the module (Mymodule), I want to display the link in the home page so I can access to Mymodule functionnality directly
how can I achieve this (without disabling the keys generation)?
I have already tried the following code, but I get redurected to the dashboard:
<?php $key = Mage::getSingleton('adminhtml/url')->getSecretKey("acompany_mymodule/index/","index"); ?> <a href="<?php echo Mage::helper("adminhtml")->getUrl("acompany_mymodule/index/index/",array("key" => $key)); ?>">My action </a>
-
Matthias Kleine over 9 yearsWell done - does this also work in frontend? I need this, because I want to create an email with a link to the specific backend entity. Or is it required to use app emulation in this case?
-
Tyler V. over 8 yearsFYI: Depending on the
config.xml
router settings of the module in question, you may need to prefix the string ingetUrl()
withadminhtml/
. For instance,Mage::helper("adminhtml")->getUrl('adminhtml/system_convert_profile/edit', array('id'=>10));
-
Hudson over 7 yearsShouldn't it be
Mage::helper('adminhtml')->getUrl('adminhtml/controller_name/action_name');
?