Magento: generating url for a backend action (with

2019-03-11 03:47发布

问题:

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>

回答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.



回答2:

use following code for get url with secret code

Mage::helper("adminhtml")->getUrl("adminshipper/process/index");

Please refer to the following article: Generating Backend-Admin URL With Key and Parameters in Magento.

DON'T USE anything else than adminhtml/ as start of the url, because magento 1.9.2.2 forbids everything else.



回答3:

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/');


标签: php url magento