2015-04-03 146 views
1

我正在使用adminhtml.xml在Magento管理員中創建一個菜單的模塊。如何將外部URL鏈接設置爲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> 

當我檢查其添加當前域名在外部網址之前。例如:http://mydomainname.com/https://externalurl.com

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

回答

3

裏面<action>標籤你可以把module/controller/action你的模塊。

然後創建這個動作,並把這樣的事情:

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

在Magento的控制器操作的標準重定向實現見Mage_Core_Controller_Varien_Action::_redirectUrl

1

不幸的是,這是不可能的。爲了這個工作,你必須重寫Mage_Adminhtml_Block_Page_Menu類。

我建議修改_buildMenuArray方法,以支持「external_url」配置在adminhtml.xml像這樣

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> 

記住重寫類並且不要修改核心類。

+1

儘可能防止類覆蓋。 – hakre 2015-04-03 19:42:39

+0

你說的對,當然可以的話,應該防止課程重寫。在這種情況下,這是不可能的,因爲這是按照原始問題的要求在新窗口中打開鏈接('target ='_blank'')的唯一方法。 – Rinda 2015-04-07 10:20:58

-1
<?php 
$url = 'http://example.com'; 
$this->_redirectUrl('http://example.com'); 

Mage::app()->getResponse()->setRedirect($url)->sendResponse(); 

Mage::app()->getFrontController()->getResponse()->setRedirect($url)->sendResponse(); 
?> 
+0

你的答案的任何介紹,它可能是?只是發佈代碼是沒有提供信息的 – Farside 2016-07-26 09:49:05

相關問題