69058

How to set external URL link to Magento admin menu

Question:

I am working on a module where I have created one menu in Magento admin using adminhtml.xml.

Now I want to link one of the menu to an external URL and set target="blank". But I'm not sure how to do it in adminhtml.xml. Here is my code.

<?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>

When i am checking its adding current domain name before external url. ex: <a href="http://mydomainname.com/https://externalurl.com" rel="nofollow">http://mydomainname.com/https://externalurl.com</a>

I am wondering how to set only external URL ?

Answer1:

Inside <action> tag you can put module/controller/action of your module.

Then create this action and put something like this:

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

See <a href="https://github.com/OpenMage/magento-mirror/blob/magento-1.9/app/code/core/Mage/Core/Controller/Varien/Action.php#L674" rel="nofollow">Mage_Core_Controller_Varien_Action::_redirectUrl</a> for the standard redirect implementation in Magento controller actions.

Answer2:

Unfortunately, this is not possible out of the box. For this to work you'd have to override Mage_Adminhtml_Block_Page_Menu class.

I'd suggest to modify the _buildMenuArray method to support a "external_url" config option in adminhtml.xml like so

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'; }

and getMenuLevelmethod respectively

$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;

Then you can add to your configuration

<?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>

Remember to <strong>rewrite the class</strong> and do not modify the core class.

Answer3:

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

Recommend

  • NGINX: How to setup multiple port in one server or domain name
  • How do I find and replace a part of a string variable in Stata?
  • Nginx - how to redirect (301) www to non-www correctly for bot http /https?
  • How to get rid of extra spaces in a textarea?
  • How to upload file on another domain?
  • Are there algorithms for putting a digest into the file being digested?
  • Play Framework nested form errors missing
  • calling a fragment from fragment
  • Regex for URL rewrite with optional query string parameters
  • What is this strange character in chrome's resource css viewer?
  • How to repeat sections of a SQL query across UNIONs? (DRY in SQL)
  • What is this error in fortran and how to stop the program when it occurs?
  • Action Pack components in Rails
  • Can you pass an array from javascript to asp.net mvc controller action without using a form?
  • redirect_to root_url and return unless @user.activated
  • Getting the scrolling offset when storing coordinates
  • Bootstrap (v3.3.4) glyphicons not displayed in IE when refresh page (F5)
  • jwtBearer bearer token with rc-1 update to ASP.Net 5
  • Implementing “partial void” in VB
  • How do I include a SWC in an AS2 Flash project?
  • Sending HTML Form Data to Spring REST Web Service
  • How to add a focus style to an editable ComboBox in WPF
  • How do I superscript characters in a UIButton?
  • Should I or shouldn't I use the CachingConnectionFactory with hornetq 2.4.1
  • Email verification using google app script and google forms
  • Is my CUDA kernel really runs on device or is being mistekenly executed by host in emulation?
  • what is the difference between the asp.net mvc application and asp.net web application
  • bootstrap to use multiple ng-app
  • PHP: When would you need the self:: keyword?
  • How to get icons for entities from eclipse?
  • Python: how to group similar lists together in a list of lists?
  • Acquiring multiple attributes from .xml file in c#
  • How to set the response of a form post action to a iframe source?
  • How do you join a server to an Active Directory (domain)?
  • Understanding cpu registers
  • Change div Background jquery
  • Turn off referential integrity in Derby? is it possible?
  • JaxB to read class hierarchy
  • reshape alternating columns in less time and using less memory
  • How can I use threading to 'tick' a timer to be accessed by other threads?