Creating an Admin Menu Tab with iFrame in Magento
In this tutorial, we will guide you through adding a new menu tab in the Magento admin backend that displays an external web page using an iframe. This allows your users to access both Magento and their CRM from a single view without leaving the admin area.
Prerequisites:
- Magento version 1.5.1.0 or later
- Basic familiarity with PHP and XML
Step 1: Create the Configuration File
First, you need to create a new configuration file in your custom module folder:
app/code/local/YourCompany/YourModule/etc/config.xml
Add the following content to this file:
<config>
<adminhtml>
<menu>
<your_module translate="title" module="your_module">
<title>CRM Interface</title>
<sort_order>500</sort_order>
<children>
<interface>
<title>Interface</title>
<url path="*/index/index"/>
<sort_order>1</sort_order>
</interface>
</children>
</your_module>
</menu>
</adminhtml>
</config>
Replace YourCompany and YourModule with your actual vendor name and module name. This configuration file tells Magento to add a new menu item called “CRM Interface” under the root level, with the “Interface” child tab that links to our custom controller.
Step 2: Create the Custom Controller
Create a new controller in:
app/code/local/YourCompany/YourModule/controllers/Adminhtml/IndexController.php
Implement the indexAction method as follows:
public function indexAction()
{
$this->loadLayout();
$this->getLayout()->getBlock('head')->setTitle($this->__('CRM Interface'));
$this->renderLayout();
}
This controller loads a new layout and sets the page title.
Step 3: Add the iFrame to the Layout
Create a new XML layout file in:
app/design/adminhtml/default/default/layout/your_module.xml
Add the following content inside the <layout> tag:
<layout version="0.1.0">
<adminhtml_index_index>
<reference name="content">
<block type="core/text" name="crm_iframe">
<action method="setText"><text><![CDATA[
<iframe src="http://your-crm-url.com" width="100%" height="600"></iframe>
]]></text></action>
</block>
</reference>
</adminhtml_index_index>
</layout>
Replace http://your-crm-url.com with the actual URL of your CRM page.
Step 4: Compile and Clear Cache
After making these changes, you need to compile code pools and clear cache:
php shell/compiler.php
php shell/cache.php --clear-mage-tags
Conclusion:
By following this step-by-step guide, you have successfully added a new menu tab in the Magento admin area that displays an external web page using an iframe. This feature allows your users to stay within the Magento admin interface while accessing their CRM system.
For more advanced customization and development tips, consider exploring the resources available at LaravelCompany. Our team specializes in Magento development services that can help you optimize performance, enhance security, and build custom extensions tailored to your business needs.