How to Create A Magento Adminhtml Controller in Magento Extension

Creating your own Adminhtml pages in Magento.

1. How to Create Adminhtml Controller in Magento ExtensionCreating your own Adminhtml pages in Magento.  Hendy Irawan at Bippo Indonesia
2. URL Structurehttp://demo.bippo.co.id /admin/module/controller/action/key/***
3. Create Modules etc/config.xml 1.0.0
4. Activate in etc/modules/ {company}_{module}.xml true community
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. Router Config… admin Bippo_MyBanner mybanner … Bippo/MyBanner/etc/config.xml
7. “Raw” Action
8. Simple Actionpublic function helloAction(){ echo “Hello World”;}
9. Admin Panel Menu Link

Banner Creatives mybanner/adminhtml_creatives

Bippo/MyBanner/etc/config.xml
10. Test it Go to Admin Panel Navigate to “Catalog > Banner Creatives”
11. Layout-based Action
12. Layout Config mybanner.xml Bippo/MyBanner/etc/config.xml
13. Layout XML bippomybanner.xml
14. Load Layout in Actionpublic function smallAction(){ $this->loadLayout(); $this->renderLayout();}
15. Test /mybanner/display/small
16. Get Adminhtml Action URL from PHP$url = Mage::helper(adminhtml) ->getUrl(mybanner/adminhtml_creatives/edit , array(city=>Bandung) );
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. Process InputgetUrl(mybanner/adminhtml_creatives/edit);

Integer 1
  • 19. Is Form POST ?$this­>getRequest()­>isPost()
    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. Get & Set Session Variables$session = Mage::getSingleton(core/session);// get$token = $session->getAccessToken();// set$session->setAddress(Rereongan Sarupi);
    22. Support Messages Block$this­>_initLayoutMessages(adminhtml/session);Other choices: customer/session catalog/session checkout/session
    23. Add MessageMage::getSingleton(customer/session) ->addSuccess(“$int1 * $int2 = $result”);
    24. Display Message in PHTML Templateecho $this­>getMessagesBlock()­>getGroupedHtml();
    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

    We got this blog from www.slideshare.net for blog more information Click Here

    Leave a Reply