php Magento:为后端操作生成 url(带密钥)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11450146/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 00:33:04  来源:igfitidea点击:

Magento: generating url for a backend action (with key)

phpurlmagento

提问by Hidalgo

I am working on a demo Magento store (CE v1.7)

我正在开发一个演示 Magento 商店 (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

我想为模块 (Mymodule) 的控制器 (index) 的操作 (index) 生成链接,我想在主页中显示链接,以便我可以直接访问 Mymodule 功能

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>

回答by blmage

A secret key should automatically be added to the URL when using

使用时应自动将密钥添加到 URL

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.

除了adminhtml/作为 url 的开头之外,不要使用任何其他内容,因为 magento 1.9.2.2 禁止其他所有内容。

回答by Hidalgo

use following code for get url with secret code

使用以下代码获取带有密码的 url

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

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

请参阅以下文章:在 Magento 中使用密钥和参数生成后端管理 URL

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

除了adminhtml/作为 url 的开头之外,不要使用任何其他内容,因为 magento 1.9.2.2 禁止其他所有内容。

回答by Louis B.

The other solutions did not work for me as they did not include the Admin Panel base URL (adminby default). I had to do it like this to get the correct URL:

其他解决方案对我不起作用,因为它们不包含管理面板基本 URL(默认为admin)。我必须这样做才能获得正确的 URL:

Mage::helper('adminhtml')->getUrl('adminhtml/name_of_custom_extension/name_of_controller/');