How to Create A Magento Adminhtml Controller in Magento Extension

23,870 views
23,211 views

Published on

Creating your own Adminhtml pages in Magento.

4 Comments
8 Likes
Statistics
Notes
  • I have found many features Magento 1.x & Magento 2 modules that will be useful for us. In that Advanced Newsletter Popup – Extension for Magento, Advanced Category Slider – Extension for Magento, Most Viewed & Sold Product Count – Extension for Magento, Size Chart – Extension for Magento i had like the most. https://goo.gl/tRX8UD
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Nice and Informative presentation. I found I site from where you can get 100 plus Magento extensions which supports all Magento latest versions http://www.fmeextensions.com
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • slide 13 not show complete path of bippomybanner.xml
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Nice Info- Thanks to Share! http://www.mindbusy.com
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
23,870
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
215
Comments
4
Likes
8
Embeds 0
No embeds

No notes for slide

How to Create A Magento Adminhtml Controller in Magento Extension

  1. 1. How to Create Adminhtml Controller in Magento ExtensionCreating your own Adminhtml pages in Magento.  Hendy Irawan at Bippo Indonesia
  2. 2. URL Structurehttp://demo.bippo.co.id    /admin/module/controller/action/key/***
  3. 3. Create Modules etc/config.xml<?xml version="1.0" encoding="UTF-8"?><config> <modules> <Bippo_MyBanner > <version>1.0.0</version> </Bippo_MyBanner > </modules></config>
  4. 4. Activate in etc/modules/ {company}_{module}.xml<?xml version="1.0" encoding="UTF-8"?><config> <modules> <Bippo_MyBanner > <active>true</active> <codePool>community</codePool> </Bippo_MyBanner > </modules></config>
  5. 5. Controller Class PHP Codeclass Bippo_MyBanner_Adminhtml_Creatives Controller extends Mage_Adminhtml_Controller_Action{ public function helloAction(){ }} Bippo/MyBanner/controllers/Adminhtml/CreativesController.php
  6. 6. Router Config...<admin> <routers> <mybanner> <use>admin</use> <args> <module>Bippo_MyBanner</module> <frontName>mybanner</frontName> </args> </mybanner> </routers></admin>... Bippo/MyBanner/etc/config.xml
  7. 7. "Raw" Action
  8. 8. Simple Actionpublic function helloAction(){    echo "Hello World";}
  9. 9. Admin Panel Menu Link<adminhtml> <menu> <catalog> <children> <mybanner_admincreatives translate="title" module="mybanner"> <title>Banner Creatives </title> <action>mybanner/adminhtml_creatives </action> </mybanner_admincreatives > </children> </catalog> </menu></adminhtml> Bippo/MyBanner/etc/config.xml
  10. 10. Test it Go to Admin Panel Navigate to "Catalog > Banner Creatives"
  11. 11. Layout-based Action
  12. 12. Layout Config<adminhtml> <layout> <updates> <mybanner> <file>mybanner.xml</file> </mybanner> </updates> </layout> </adminhtml> Bippo/MyBanner/etc/config.xml
  13. 13. Layout XML<?xml version="1.0" encoding="UTF-8"?> <layout version="0.1.0"> <arithmetic_integer_multiply> <reference name="root"> <action method="setTemplate"> <template>page/1column.phtml</template> </action> </reference> <reference name="content"> <block type="core/template" name="arithmetic_integer_multiply" template="arithmetic/integer/multiply.phtml"></block> </reference> </arithmetic_integer_multiply> </layout> bippomybanner.xml
  14. 14. Load Layout in Actionpublic function smallAction(){ $this->loadLayout(); $this->renderLayout();}
  15. 15. Test /mybanner/display/small
  16. 16. Get Adminhtml Action URL from PHP$url = Mage::helper(adminhtml) ->getUrl(mybanner/adminhtml_creatives/edit , array(city=>Bandung) );
  17. 17. GET & Post Variables$request = Mage::app()->getRequest();// GET$productId = $request->getParam(product_id, 44);// 44 = default value if "product_id" not specified// POST, method 1$description = $request->getPost(description, "hi");// POST, method 2$postData = $request->getPost();$description = $postData[description];
  18. 18. Process Input<?php$url = Mage::helper(adminhtml)->getUrl(mybanner/adminhtml_creatives/edit);<form action="<?php echo $url ?>" method="post"> <?php echo $this->getBlockHtml(formkey)?> <fieldset> <ul> <li> <label for="int1">Integer 1</label> <input type="text" id="int1" name="int1" /> </li> <li> <label for="int2">Integer 2</label> <input type="text" id="int2" name="int2" /> </li> <li><input type="submit" value="Multiply" /></li> </ul> </fieldset></form>
  19. 19. Is Form POST ?$this­>getRequest()­>isPost()
  20. 20. Process POST Parameterspublic function multiplyAction(){ if ($this->getRequest()->isPost()){ $int1 = $this->getRequest()->getPost(int1); $int2 = $this->getRequest()->getPost(int2); $result = $int1 * $int2; Mage::getSingleton(customer/session) ->addSuccess("$int1 * $int2 = $result"); } $this->loadLayout(); $this->_initLayoutMessages(customer/session); $this->renderLayout();}
  21. 21. Get & Set Session Variables$session = Mage::getSingleton(core/session);// get$token = $session->getAccessToken();// set$session->setAddress(Rereongan Sarupi);
  22. 22. Support Messages Block$this­>_initLayoutMessages(adminhtml/session);Other choices: customer/session catalog/session checkout/session
  23. 23. Add MessageMage::getSingleton(customer/session) ->addSuccess("$int1 * $int2 = $result");
  24. 24. Display Message in PHTML Templateecho $this­>getMessagesBlock()­>getGroupedHtml();
  25. 25. References http://www.magentocommerce.com/wiki/5_­_modules_and_development/0_­_module_d http://www.magentocommerce.com/boards/viewthread/19386/ http://inchoo.net/ecommerce/magento/getting­started­with­building­admin­module­in­ma

×