Ravinder Singh
Ravinder Singh

Reputation: 3133

How to add custom tab in left sidebar to my custom page in admin section in magento module?

I am very new to Magento, just started Magento before 4 days but i am given the task to develop a Magento extension. So i am reading over the internet and creating it.

Now the problem i am having is i want to add a custom left sidebar tabs just like it is under
System->Configuration.

I have tried a lot but no success. Please help me.

Here's my config.xml

<?xml version="1.0"?>
<config>
<!-- turn on our module, required for install support -->
<modules>
<Gwb_Magecrmsync>
    <version>0.1.0</version>
</Gwb_Magecrmsync>
</modules>
<frontend>
<routers>
    <magecrmsync>
        <use>standard</use>
        <args>
            <module>Gwb_Magecrmsync</module>
            <frontName>magecrmsync</frontName>
        </args>
    </magecrmsync>
</routers>
<layout>
    <updates>
        <magecrmsync>
            <file>adminhtml.xml</file>
        </magecrmsync>
    </updates>
</layout>
</frontend>
<admin>
<routers>
    <magecrmsync>
        <use>admin</use>
        <args>
            <module>Gwb_Magecrmsync</module>
            <frontName>magecrmsync</frontName>
        </args>
    </magecrmsync>
</routers>
</admin>
<adminhtml>
<menu>
    <menu1 translate="title" module="magecrmsync">
        <title>Synchronize</title>
        <sort_order>999</sort_order>
        <children>
            <menuitem1 module="magecrmsync">
                <title>Customers</title>
                <action>magecrmsync/adminhtml_magecrmsync</action>
            </menuitem1>
            <menuitem2 module="magecrmsync">
                <title>Orders</title>
                <action>magecrmsync/adminhtml_magecrmsync</action>
            </menuitem2>
            <menuitem3 module="magecrmsync">
                <title>Products</title>
                <action>magecrmsync/adminhtml_magecrmsync</action>
            </menuitem3>
        </children>
    </menu1>
</menu>
<acl>
    <resources>
        <admin>
            <children>
                <menu1 translate="title" module="magecrmsync">
                    <title>Synchronize</title>
                    <sort_order>999</sort_order>
                    <children>
                        <menuitem1>
                            <title>Customers</title>
                        </menuitem1>
                        <menuitem2>
                            <title>Orders</title>
                        </menuitem2>
                        <menuitem3>
                            <title>Products</title>
                        </menuitem3>
                    </children>
                </menu1>
            </children>
        </admin>
    </resources>
</acl>
</adminhtml>
<global>
<!-- turn on models -->
<models>
    <magecrmsync>
        <class>Gwb_Magecrmsync_Model</class>
        <resourceModel>Magecrmsync_mysql4</resourceModel>
    </magecrmsync>
</models>
<!-- turn on models -->

<!-- turn on database connections -->
<resources>
<!-- setup is needed for automatic installation -->
    <magecrmsync_setup>
        <use>default_setup</use>
    </magecrmsync_setup>
    <magecrmsync_write>
        <use>default_write</use>
    </magecrmsync_write>
    <magecrmsync_read>
        <use>default_read</use>
    </magecrmsync_read>
</resources>

<blocks>
    <magecrmsync>
        <class>Gwb_Magecrmsync_Block</class>
    </magecrmsync>
</blocks>

<helpers>
    <magecrmsync>
        <class>Gwb_Magecrmsync_Helper</class>
    </magecrmsync>
</helpers>

<layout>
    <magecrmsync>
        <file>adminhtml.xml</file>
    </magecrmsync>
</layout>

</global>
</config>

Please tell me where i am missing something which is not letting me add tabs to the left on my custom page. Please correct me if i am wrong anywhere.


Edit
This is my system.xml file. This is letting me add custom tab under System->Configuration but i want it on my custom page which is separate then Configuration Menu.

<?xml version="1.0"?>
<config>
<tabs>
    <sidetab translate="label" module="magecrmsync">
        <label>My Custom Tab</label>
        <sort_order>200</sort_order>
    </sidetab>
</tabs>
<sections>
    <sidetab translate="label" module="magecrmsync">
        <class>separator-top</class>
        <label>My Tab</label>
        <tab>sidetab</tab>
        <sort_order>100</sort_order>
        <show_in_default>1</show_in_default>
        <show_in_website>1</show_in_website>
        <show_in_store>1</show_in_store>
        <groups>
            <sidetab_option translate="label">
                <label>sysem Tab Options</label>
                <frontend_type>text</frontend_type>
                <sort_order>10</sort_order>
                <show_in_default>1</show_in_default>
                <show_in_website>1</show_in_website>
                <show_in_store>1</show_in_store>
                <fields>
<registration_mode translate="label"> <label>On New User Signup</label>
                        <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                        <sort_order>1</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>1</show_in_store>
                    </registration_mode>
<forget_mode translate="label">
                        <label>Send Email on Forget Password</label>
                        <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                        <sort_order>1</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>1</show_in_store>
                    </forget_mode>
<purchase_mode translate="label">
                        <label>Send Email On Product Purchase</label>
                        <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                        <sort_order>1</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>1</show_in_store>
                    </purchase_mode>
                </fields>
</sidetab_option>
        </groups>
    </sidetab>
</sections>
</config>


My Controller Code :

<?php
class Gwb_Magecrmsync_Adminhtml_MagecrmsyncController extends     Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
    $this->loadLayout()
         ->_setActiveMenu('menu1')
         ->_addBreadcrumb(Mage::helper('adminhtml')->__('Synchronize Data'), Mage::helper('adminhtml')->__('Synchronize Data'))
         ->_title($this->__('Synchronize Data'));

    $block = $this->getLayout()->createBlock(
        'Mage_Core_Block_Template',
        'my_block_name_here',
        array('template' => 'magecrmsync/mainblock.phtml')
    );
    $this->getLayout()->getBlock('content')->append($block);

    $this->renderLayout();
}

}

I want to add tabs on my page just like this :

Tabs like this image has on the left side on my page not on system->configuration page.

Any help would be very much appreciated and will be helpful to me.

Thanks Ravinder

Upvotes: 4

Views: 4408

Answers (2)

MagePal Extensions
MagePal Extensions

Reputation: 17656

It seem like you are tying to create a 'left' and 'main' block within your admin controller.

$this->loadLayout();
$this->_addContent($this->getLayout()->createBlock('form/adminhtml_form_edit'))
            ->_addLeft($this->getLayout()->createBlock('form/adminhtml_form_edit_tabs'));
$this->renderLayout();


class Excellence_Form_Block_Adminhtml_Form_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
{

  public function __construct()
  {
      parent::__construct();
      $this->setId('form_tabs');
      $this->setDestElementId('edit_form'); // this should be same as the form id define above
      $this->setTitle(Mage::helper('form')->__('Product Information'));
  }

  protected function _beforeToHtml()
  {
      $this->addTab('form_section', array(
          'label'     => Mage::helper('form')->__('Item Information'),
          'title'     => Mage::helper('form')->__('Item Information'),
          'content'   => $this->getLayout()->createBlock('form/adminhtml_form_edit_tab_form')->toHtml(),
      ));

      return parent::_beforeToHtml();
  }
}

See http://www.excellencemagentoblog.com/module-development-series-magento-admin-module-part3

enter image description here

$this->_addLeft($this->getLayout()
    ->createBlock('core/text')
    ->setText('<h1>Left Block</h1>'));

$block = $this->getLayout()
    ->createBlock('core/text')
    ->setText('<h1>Main Block</h1>');           
    $this->_addContent($block);

Read more @ http://alanstorm.com/magento_admin_controllers

Upvotes: 1

Menno
Menno

Reputation: 641

I read your question to fast in my previous answer, so I'll add this new one with the correct information. You will need to make a folder structure, in which the tabs are all separated in different files.

The following link explains how to add a tab to an existing module, you might want to search for a better article yourself, as there is enough information on this to be found: http://terrani.wordpress.com/2011/01/03/magento-add-a-new-tab-on-customer-edit-page/

Another article about it: http://www.atwix.com/magento/new-tab-product-edit-page/

Upvotes: 0

Related Questions