How to call the controller from the user menu created by the extension in Magento?

I am new to Magento, and at first I was tasked with creating the Magento Extension. So I read from the Internet and create an extension. My version of Magento is 1.7.0.2.

I can create the basic structure of the extension and save the config.xml file and other files in the right place, which made my extension correctly installed in Magento, but now I want to call my controller from my menu, which I added to the main navigation in admin. This is my config.xml file, please tell me what I am doing wrong here, which does not allow me to 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 a user tab in the left sidebar to my user page in the admin section of the magento module?

Any help would be appreciated.

thanks

+4
source share
7 answers

This is what the config.xml file should look like:

 <?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 SynchronizeController.php in Gwb / Magecrmcync / controllerlers / 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.

0
source

You should try not to use all the capital for namin, in some cases. Cappial letters are used to distinguish between different classes, etc., are renamed to:

 Gwb_Magecrmsync 

Your action is incorrect, try the following:

 <action>magecrmsync/adminhtml_synchronize</action> 

You will also need a router definition for the administrator.

 <admin> <routers> <magecrmsync> <use>admin</use> <args> <module>GWB_MAGECRMSYNC</module> <frontName>magecrmsync</frontName> </args> </magecrmsync> </routers> </admin> 
+2
source

I would recommend that you change the name of your module 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> 
+1
source

Look at my configuration, maybe this 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> 
+1
source

And also rename your module to

 <Gwb_Magecrmsync> 
0
source

Check out these questions that Alan Storm answered to some of the recommendations:

Magento Custom Module How to save a variable in config.xml
and Setting a global variable in Magento, the path to the GUI?

The second question contains more detailed answers, one of which helped me with the first module that I have with the admin menu. I added the answer to the second question, trying to explain what I was doing, and included the package that I created related to my answer.

0
source

Dude, let me show you how I will be a future Magento expert. Therefore, the expert says:

In your configuration

 <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> 
  • action node represents your controller So your directory should be in Magecrmsync / controller / Adminhtml / MagecrmsyncController * make sure it extends the right class

now in this controller you call loadlayout () β†’ this guy will just load all the layout.xml files and save it in memory and renderlayout () β†’ this guy does the actual printing of the material.

  • But wait a minute. loadlayout () above does not know about our layout.xml of this our custom extension. No problem allows you to create it. So just go to design-> adminhtml-> package-> theme-> layout and put your layout.xml, which in your case is .... it's ..... oh, you don't have it in your config file .xml (since layout.xml for the administrator needs to be in the adminhtml node, you have one, but it looks like an interface, but still it isn’t because you don’t have a node interface.) Anyways suggests you might have received this so far and received a new xml layout file for you admin and put it in the adminhtml node. eg

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

Now this our new layoutitoutdarling file will reference or we can point to the classes we need for our journey. This layout file will keep a secret in what you need. yes, what will he have ????? he will have ..... Handles: -S Handles correspond to you URL (or the path to your module / controller / method) and call the material enclosed between them. for example, in this random example, there will be a handle, when you go to this block of URL block, it 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, in fact, this file (Employee / Block / Adminhtml / Employee.php) is your Grid container. Then the Grid container will point you to the Grid file (Employee / Block / Adminhtml / Employee / Grid.php). There is a difference between a Grid Container and a Grid.

Forms in magento are divided into two 4 main parts 1. FORM container 2. FORM TOPIC 3. FORM tabs 4. Valid form fields

More info on what I said here

Then, for the tabs, suppose you have placed the Add New Sexy Girl button in the "Grid Container" section. Of course, this will point to (controller) / sexyController / newAction

So now your newAction will tell you to add tabs to the left.

 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(); } 

For more information on how to add tabs and more, click here.

Yes, I have only 4 beers and I have 2 left.

Peace my dear friend is checking this site and you will also become like me .. future magento expert.

-3
source

All Articles