How to Create A Magento Adminhtml Controller in Magento Extension
Upcoming SlideShare
Loading in...5
×
 

How to Create A Magento Adminhtml Controller in Magento Extension

on

  • 11,917 views

Creating your own Adminhtml pages in Magento.

Creating your own Adminhtml pages in Magento.

Statistics

Views

Total Views
11,917
Views on SlideShare
11,915
Embed Views
2

Actions

Likes
4
Downloads
138
Comments
2

2 Embeds 2

http://fbdev.slideshare.com 1
http://localhost 1

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

12 of 2

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    How to Create A Magento Adminhtml Controller in Magento Extension How to Create A Magento Adminhtml Controller in Magento Extension Presentation Transcript

    • How to Create Adminhtml Controller in Magento ExtensionCreating your own Adminhtml pages in Magento.  Hendy Irawan at Bippo Indonesia
    • URL Structurehttp://demo.bippo.co.id    /admin/module/controller/action/key/***
    • 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>
    • 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>
    • Controller Class PHP Codeclass Bippo_MyBanner_Adminhtml_Creatives Controller extends Mage_Adminhtml_Controller_Action{ public function helloAction(){ }} Bippo/MyBanner/controllers/Adminhtml/CreativesController.php
    • 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
    • "Raw" Action
    • Simple Actionpublic function helloAction(){    echo "Hello World";}
    • 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
    • Test it Go to Admin Panel Navigate to "Catalog > Banner Creatives"
    • Layout-based Action
    • Layout Config<adminhtml> <layout> <updates> <mybanner> <file>mybanner.xml</file> </mybanner> </updates> </layout> </adminhtml> Bippo/MyBanner/etc/config.xml
    • 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
    • Load Layout in Actionpublic function smallAction(){ $this->loadLayout(); $this->renderLayout();}
    • Test /mybanner/display/small
    • Get Adminhtml Action URL from PHP$url = Mage::helper(adminhtml) ->getUrl(mybanner/adminhtml_creatives/edit , array(city=>Bandung) );
    • 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];
    • 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>
    • Is Form POST ?$this­>getRequest()­>isPost()
    • 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();}
    • Get & Set Session Variables$session = Mage::getSingleton(core/session);// get$token = $session->getAccessToken();// set$session->setAddress(Rereongan Sarupi);
    • Support Messages Block$this­>_initLayoutMessages(adminhtml/session);Other choices: customer/session catalog/session checkout/session
    • Add MessageMage::getSingleton(customer/session) ->addSuccess("$int1 * $int2 = $result");
    • Display Message in PHTML Templateecho $this­>getMessagesBlock()­>getGroupedHtml();
    • 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