Mais conteúdo relacionado Semelhante a How to Create A Magento Adminhtml Controller in Magento Extension (20) Mais de Hendy Irawan (18) How to Create A Magento Adminhtml Controller in Magento Extension1. How to Create Adminhtml
Controller in Magento Extension
Creating your own Adminhtml pages in Magento.
Hendy Irawan at Bippo Indonesia
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. Controller Class PHP Code
class Bippo_MyBanner_Adminhtml_Creatives Controller
extends Mage_Adminhtml_Controller_Action
{
public function helloAction(){
}
}
Bippo/MyBanner/controllers/Adminhtml/CreativesController.php
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
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. Test it
Go to Admin Panel
Navigate to "Catalog > Banner Creatives"
12. Layout Config
<adminhtml>
<layout>
<updates>
<mybanner>
<file>mybanner.xml</file>
</mybanner>
</updates>
</layout>
</adminhtml>
Bippo/MyBanner/etc/config.xml
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. Load Layout in Action
public 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 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>
20. Process POST Parameters
public 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');
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/gettingstartedwithbuildingadminmoduleinma