4

I am new to Magento and at first up i got the task to create Magento Extension. So i am reading from the internet and creating extension. My Magento version is 1.7.0.2.

I am able to create basic structure of extension and kept config.xml and other files at proper place which made my extension to install properly in Magento but now i want to call my controller from my menu which i added in main navigation in admin section. This is my config.xml file, please tell me what i am doing wrong here which is not letting me call my controller from my menu.

<?xml version="1.0"?>
<config>
<!-- turn on our module, required for install support -->
<modules>
<Gwb_Magecrmsync>
    <version>0.1.0</version>
</Gwb_Magecrmsync>
</modules>
<global>
<helpers>
    <magecrmsync>
        <class>Gwb_Magecrmsync_Helper</class>
    </magecrmsync>
</helpers>
<!-- 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>
<layout>
    <magecrmsync>
        <file>Magecrmsync.xml</file>
    </magecrmsync>
</layout>
</global>
<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>Synchronize</title>
                <action>magecrmsync/adminhtml_magecrmsync</action>
            </menuitem1>
        </children>
    </menu1>
</menu>
<acl>
    <resources>
        <admin>
            <children>
                <menu1 translate="title" module="magecrmsync">
                    <title>Synchronize</title>
                    <sort_order>999</sort_order>
                    <children>
                        <menuitem1>
                            <title>Synchronize</title>
                        </menuitem1>
                    </children>
                </menu1>
            </children>
        </admin>
    </resources>
</acl>
</adminhtml>
</config>

Please check my updated code here :

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

Any help would be appreciated.

Thanks

Community
  • 1
  • 1
Ravinder Singh
  • 3,113
  • 6
  • 30
  • 46
  • GWB_MAGECRMSYNC_**Model** Use Block here – dagfr Mar 05 '13 at 18:53
  • I may also suggest to not name your menu "menu". For the reste hope @R.S help would help you – dagfr Mar 05 '13 at 18:54
  • Just confusing, How he can offer 100 bounty with only 1 reputation! – Amir Mar 11 '13 at 07:30
  • This is because he had 1600 points and someone cheated with him and called moderator and they both together blocked his account for a year and deleted all his points. – Dead Man Mar 12 '13 at 06:32

7 Answers7

2

You should try not to use all capitals for a namin convension, in some cases Captial letters are used to distinguish different classes etc, rename to:

Gwb_Magecrmsync

Your action is incorrect, try this:

<action>magecrmsync/adminhtml_synchronize</action>

You also need a Router definition for the admin

<admin>
    <routers>
        <magecrmsync>
            <use>admin</use>
            <args>
                <module>GWB_MAGECRMSYNC</module>
                <frontName>magecrmsync</frontName>
            </args>
        </magecrmsync>
    </routers>
</admin>
Andrew
  • 12,617
  • 1
  • 34
  • 48
  • Hello @Andrew, i just updated my code according to your suggestion but still i am getting page not found. Please check my updated code and help me. – Ravinder Singh Mar 08 '13 at 06:22
  • Hello @Andrew, it worked, i had my controller name wrong, it is showing a page now but how can i load my mainblock.phtml file to load in view – Ravinder Singh Mar 08 '13 at 07:28
  • Can you please tell me that how can i add left sidebar navigation like it is there under System->Configuration ? – Ravinder Singh Mar 08 '13 at 08:01
  • I am able to add custom tab to system->configuration but i want it on my page. Please check my updated question here : http://stackoverflow.com/questions/15293900/how-to-add-custom-tab-in-left-sidebar-to-my-custom-page-in-admin-section-in-mage – Ravinder Singh Mar 08 '13 at 13:13
  • You can't do it like that. There will be a lot more work involved to do that, and not using the XML config. Best bet is to find a Magento module currently using a similr layout and copy the blocks over to your module and rename :) – Andrew Mar 08 '13 at 13:26
  • Can you help me or guide me in doing that, because this problem is solved for which i started bounty and it will go to you for sure because you helped me. Can you please help me again? – Ravinder Singh Mar 08 '13 at 13:27
  • Did u do anything like this in your projects? – Ravinder Singh Mar 08 '13 at 13:30
  • I've done just about everything you can imagine with Magento :) I will add a guide when i've got a bit more time available – Andrew Mar 08 '13 at 13:36
  • until then I advise to look at a similar block, Customers for example: Mage/Adminhtml/Block/Customer/* Take a look at the edit/tab blocks :) – Andrew Mar 08 '13 at 13:39
  • Ok Man, but when you do add guide, don't forget to tell me about it please. I would like to thoroughly read it. – Ravinder Singh Mar 08 '13 at 13:43
1

I would recommend that you change your module name from MAGECRMSYNC to MageCrmSync

Try

.....
<admin>
    <routers>
        <magecrmsync>
            <use>admin</use>
            <args>
                <module>GWB_MAGECRMSYNC</module>
                <frontName>magecrmsync</frontName>
            </args>
        </magecrmsync>
    </routers>
</admin>
<adminhtml>
<menu>
    <magecrmsync translate="title" module="magecrmsync">
        <title>Synchronize</title>
        <sort_order>60</sort_order>
        <children>
            <menuitem module="magecrmsync">
                <title>Menu item 1</title>
                <action>magecrmsync/adminhtml_synchronize</action>
            </menuitem>
        </children>
    </magecrmsync>
</menu>
<acl>
    <resources>
       <all>
            <title>Allow Everything</title>
        </all>
        <admin>
            <children>
                <magecrmsync translate="title" module="magecrmsync">
                    <title>Sychronize</title>
                    <sort_order>60</sort_order>
                    <children>
                        <menuitem>
                            <title>Menu item 1</title>
                        </menuitem>
                    </children>
               </magecrmsync>
           </children>
       </admin>
   </resources>
</acl>
<adminhtml>
</config>
MagePal Extensions
  • 17,646
  • 2
  • 47
  • 62
1

Have a look at my config maybe it will help you.

<?xml version="1.0"?>
<config>
    <modules>
        <Tibdev_Paypal>
            <version>1.1.0</version>
        </Tibdev_Paypal>
    </modules>

    <global>
        <models>
           ...
        </models>

        <helpers>
            ...
        </helpers>

        <resources>
            ...
        </resources>

    </global>

    <admin>
        <routers>
            ...
        </routers>
    </admin>


    <adminhtml>
        <menu>
            <menu1 translate="title" module="Paypal">
                <title>Tigerbytes GmbH</title>
                <sort_order>999</sort_order>
                <children>
                    <menuitem1 module="Paypal">
                        <title>Paypal 10413 Fix</title>
                        <action>tibdevpaypal/adminhtml_form</action>
                    </menuitem1>
                </children>
            </menu1>
        </menu>
        <acl>
            <resources>
                <admin>
                    <children>
                        <menu1 translate="title" module="Paypal">
                            <title>Tigerbytes GmbH</title>
                            <sort_order>999</sort_order>
                            <children>
                                <menuitem1>
                                    <title>Paypal 10413 Fix</title>
                                </menuitem1>
                            </children>
                        </menu1>
                    </children>
                </admin>
            </resources>
        </acl>


        <layout>
            <updates>
                ...
            </updates>
        </layout>

        <translate>
            <modules>
                ...
            </modules>
        </translate>

    </adminhtml>

</config>
Andre Aus B
  • 511
  • 5
  • 18
  • Hey @Andre, i copied your code and again created a package extension and installed it but it didn't add menu to my navigation. I don't understand what is going on. I have tried so many things but nothing is happening. – Ravinder Singh Mar 07 '13 at 05:14
  • Can you upload your stuff to github, so that we can check your code?!? – Andre Aus B Mar 07 '13 at 08:38
  • Can you also tell me how can we create a module name xml file (GWB_MAGECRMSYNC.xml) in /app/etc/modules/ ? Because we can't manually keep it on everyone's computer when they will install the extensions so there must be some way to do it. – Ravinder Singh Mar 07 '13 at 11:33
  • Hey @Andre, I have finally added the menu in the navigation. thanks to you. But now my problem is this that how should i call my controller so that i can see the view i want on that menu. I updated my working config.xml file. – Ravinder Singh Mar 07 '13 at 12:29
  • You have to configure an admin router, create an action controller and use the adress of the router as action in your menu. ;-) – Andre Aus B Mar 07 '13 at 14:21
  • Hello @Andre Aus B, i am able to show view on my page, now i want to add left sidebar navigation to my page just the way it is in System->Configuration. Can you please tell me how to do it. I tried by adding tab and section to the system.xml but it is not working. :( – Ravinder Singh Mar 08 '13 at 10:23
  • Please check my updated code here : http://stackoverflow.com/questions/15293900/how-to-add-custom-tab-in-left-sidebar-to-my-custom-page-in-admin-section-in-mage – Ravinder Singh Mar 08 '13 at 13:13
0

And also rename your module to

<Gwb_Magecrmsync>
Andre Aus B
  • 511
  • 5
  • 18
  • Hello @Andre, above code is not letting me add menu to navigation. i have updated my code in question. Please check it and let me know the mistake i am doing – Ravinder Singh Mar 06 '13 at 08:37
0

Check these SO questions that Alan Storm answered for some guidance, too:
Magento Custom Module How to store variable in config.xml
and Setting a global variable in Magento, the GUI way?

The second question has more thorough answers, one of which helped me with the first module I have with Admin menus. I added an answer to the 2nd question, attempting to further explain what I was doing, and included the package I created related to my answer.

Community
  • 1
  • 1
Krista K
  • 21,503
  • 3
  • 31
  • 43
  • Please check my updated code here : http://stackoverflow.com/questions/15293900/how-to-add-custom-tab-in-left-sidebar-to-my-custom-page-in-admin-section-in-mage – Ravinder Singh Mar 08 '13 at 13:14
0

This is how the config.xml should be :

<?xml version="1.0"?>
<config>
<!-- turn on our module, required for install support -->
<modules>
<Gwb_Magecrmsync>
    <version>0.1.0</version>
</Gwb_Magecrmsync>
</modules>
<global>
<helpers>
<magecrmsync>
    <class>Gwb_Magecrmsync_Helper</class>
</magecrmsync>
</helpers>
<!-- 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>
<layout>
<magecrmsync>
    <file>Magecrmsync.xml</file>
</magecrmsync>
</layout>
</global>
<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>Synchronize</title>
            <action>magecrmsync/adminhtml_synchronize</action>
        </menuitem1>
    </children>
</menu1>
</menu>
<acl>
<resources>
    <admin>
        <children>
            <menu1 translate="title" module="magecrmsync">
                <title>Synchronize</title>
                <sort_order>999</sort_order>
                <children>
                    <menuitem1>
                        <title>Synchronize</title>
                    </menuitem1>
                </children>
            </menu1>
        </children>
    </admin>
</resources>
</acl>
</adminhtml>
</config>

And after that create a SynchronizeController.php in Gwb/Magecrmcync/controllers/Adminhtml :

class Gwb_Magecrmsync_Adminhtml_SynchronizeController extends Mage_Adminhtml_Controller_Action
{
    public function indexAction()
    {
        $this->loadLayout();
        $this->renderLayout();
    }
}

And it will work the way you want it.

Dead Man
  • 2,880
  • 23
  • 37
-3

Dude let me show you the way I am the future Magento expert. So the expert says:

In your config

<menu1 translate="title" module="magecrmsync">
        <title>Synchronize</title>
        <sort_order>999</sort_order>
        <children>
            <menuitem1 module="magecrmsync">
                <title>Synchronize</title>
                <action>magecrmsync/adminhtml_magecrmsync</action>
            </menuitem1>
        </children>
    </menu1>
  1. action node represent your controller So here your directory has to be in Magecrmsync/controllers/Adminhtml/MagecrmsyncController *make sure it's extending the right class

now in this controller you will call the loadlayout() -> this guy just load all the layout.xml files and keep it in memory and renderlayout() -> this guy do the actual printing of the stuff.

  1. But wait a minute. loadlayout() above does not know about our layout.xml of this our custom extension. No problem lets create one. So simply go to design->adminhtml->package->theme->layout and place your layout.xml which in your case is .... is..... oh you don't have that in your config.xml (because layout.xml for admin has to be in adminhtml node, you have one but that seems to be for frontend but still that not right either because you don't have front end node.) Anyways lets assume you you might have got this by now and got a new layout xml file for you admin and placed it in adminhtml node. for example

    <adminhtml>
    <layout>
        <updates>
            <services>
                <file>layitoutdarling.xml</file>
            </services>
        </updates>
    </layout> </adminhtml>
    

Now this our new layoutitoutdarling file will reference or we can say points to classes which we need for our journey. This layout file will hold the secret to what you need. yes what it gonna have ????? it wil have the ... the .. Handles :-S Handles match you URL (or path to your mod/controller/method) and call the stuff enclosed in between them. eg in this random example is a handle, when you go to that url block class will be called whose path is Employee/Block/Adminhtml/Employee.php

<?xml version="1.0"?>
<layout version="0.1.0">
    <employee_adminhtml_employee_index>
        <reference name="content">
            <block type="employee/adminhtml_employee" name="employee" />
        </reference>
    </employee_adminhtml_employee_index>
</layout>

Now actually this file(Employee/Block/Adminhtml/Employee.php) is your Grid container. Then Grid container will points you to Grid file(Employee/Block/Adminhtml/Employee/Grid.php). There is a difference between a Grid Container and Grid.

Forms in magento are divided in two 4 basic parts 1. FORM Container 2. FORM tag 3. FORM Tabs 4. Actual Form Fields

More info on whatever I have said is here

Then for Tabs Suppose you have placed Add New Sexy Girl button in the Grid Container section. Of Course it will point to a (controller) /sexyController/newAction

So now your newAction will points you to add the tabs on the left handside.

public function newAction(){
$this->loadLayout();
$this->_addContent($this->getLayout()->createBlock('form/adminhtml_form_edit'))
(_addLeft() here we are adding tabs)
                ->_addLeft($this->getLayout()->createBlock('form/adminhtml_form_edit_tabs'));
$this->renderLayout();
}

Detailed information on how to add tabs and more click here

Yea I just had 4 beers and still have 2 left.

Rest my dear friend check that website and you will also become like me .. a future magento expert.

Ricky Sharma
  • 1,839
  • 3
  • 24
  • 44