如何将外部 URL link 设置为 Magento 管理菜单
How to set external URL link to Magento admin menu
我正在开发一个模块,我在 Magento 管理中使用 adminhtml.xml
创建了一个菜单。
现在我想link其中一个菜单到外部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 ?
不幸的是,开箱即用是不可能的。为此,您必须覆盖 Mage_Adminhtml_Block_Page_Menu
class.
我建议修改 _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';
}
和getMenuLevel
方法分别
$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>
记得重写class并且不要修改核心class。
在 <action>
标签内,您可以放置模块的 module/controller/action
。
然后创建这个动作并放置如下内容:
public function locationAction()
{
$this->_redirectUrl('http://www.example.com/');
}
请参阅 Mage_Core_Controller_Varien_Action::_redirectUrl
以了解 Magento 控制器操作中的标准重定向实现。
<?php
$url = 'http://example.com';
$this->_redirectUrl('http://example.com');
Mage::app()->getResponse()->setRedirect($url)->sendResponse();
Mage::app()->getFrontController()->getResponse()->setRedirect($url)->sendResponse();
?>
我正在开发一个模块,我在 Magento 管理中使用 adminhtml.xml
创建了一个菜单。
现在我想link其中一个菜单到外部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 ?
不幸的是,开箱即用是不可能的。为此,您必须覆盖 Mage_Adminhtml_Block_Page_Menu
class.
我建议修改 _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';
}
和getMenuLevel
方法分别
$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>
记得重写class并且不要修改核心class。
在 <action>
标签内,您可以放置模块的 module/controller/action
。
然后创建这个动作并放置如下内容:
public function locationAction()
{
$this->_redirectUrl('http://www.example.com/');
}
请参阅 Mage_Core_Controller_Varien_Action::_redirectUrl
以了解 Magento 控制器操作中的标准重定向实现。
<?php
$url = 'http://example.com';
$this->_redirectUrl('http://example.com');
Mage::app()->getResponse()->setRedirect($url)->sendResponse();
Mage::app()->getFrontController()->getResponse()->setRedirect($url)->sendResponse();
?>