如何设置外部URL链接到Magento管理菜单


How to set external URL link to Magento admin menu

我正在开发一个模块,在该模块中,我使用adminhtml.xml在Magento管理中创建了一个菜单。

现在我想将其中一个菜单链接到一个外部URL并设置target="blank"。但我不知道如何在adminhtml.xml中做到这一点。这是我的密码。

<?xml version="1.0"?>
<config>
    <menu>
        <system>
            <children>
                <convert translate="title">
                    <children>
                        <importmagmi translate="title" module="importexport">
                            <title>MagMi Importer</title>
                            <action><url helper="https://externalurl.com"/></action>
                            <sort_order>100</sort_order>
                        </importmagmi>
                    </children>
                </convert>
            </children>
        </system>
    </menu>
</config>

当我检查它在外部url之前添加当前域名时。例如:http://mydomainname.com/https://externalurl.com

我想知道如何只设置外部URL?

<action>标签中,您可以放置模块的module/controller/action

然后创建这个动作,并放一些类似的东西:

public function locationAction()
{
    $this->_redirectUrl('http://www.example.com/');
}

有关Magento控制器操作中的标准重定向实现,请参阅Mage_Core_Controller_Varien_Action::_redirectUrl

不幸的是,这不是开箱即用的。要使其工作,您必须覆盖Mage_Adminhtml_Block_Page_Menu类。

我建议修改_buildMenuArray方法,以支持adminhtml.xml中的"external_url"配置选项,就像一样

if( $child->external_url ) {
    $menuArr['url'] = (string)$child->external_url;
    $menuArr['is_external'] = true;
} 
elseif ($child->action) {
    $menuArr['url'] = $this->_url->getUrl((string)$child->action, array('_cache_secret_key' => true));
} else {
    $menuArr['url'] = '#';
    $menuArr['click'] = 'return false';
}

和CCD_ 9方法

$html .= '<li ' . (!empty($item['children']) ? 'onmouseover="Element.addClassName(this,''over'')" '
            . 'onmouseout="Element.removeClassName(this,''over'')"' : '') . ' class="'
            . (!$level && !empty($item['active']) ? ' active' : '') . ' '
            . (!empty($item['children']) ? ' parent' : '')
            . (!empty($level) && !empty($item['last']) ? ' last' : '')
            . ' level' . $level . '"> <a ' . ($item['is_external'] ? 'target="_blank" ' : '') . 'href="' . $item['url'] . '" '
            . (!empty($item['title']) ? 'title="' . $item['title'] . '"' : '') . ' '
            . (!empty($item['click']) ? 'onclick="' . $item['click'] . '"' : '') . ' class="'
            . ($level === 0 && !empty($item['active']) ? 'active' : '') . '"><span>'
            . $this->escapeHtml($item['label']) . '</span></a>' . PHP_EOL;

然后你可以添加到你的配置

<?xml version="1.0"?>
<config>
    <menu>
        <system>
            <children>
                <convert translate="title">
                    <children>
                        <importmagmi translate="title" module="importexport">
                            <title>MagMi Importer</title>
                            <external_url>https://externalurl.com</external_url>                                <sort_order>100</sort_order>
                        </importmagmi>
                    </children>
                </convert>
            </children>
        </system>
    </menu>
</config>

记住重写类,不要修改核心类。

<?php
$url = 'http://example.com';
$this->_redirectUrl('http://example.com');
Mage::app()->getResponse()->setRedirect($url)->sendResponse();
Mage::app()->getFrontController()->getResponse()->setRedirect($url)->sendResponse();
?>