How to create a magento controller in magento extension

18,161 views

Published on

Published in: Technology, News & Politics
2 Comments
4 Likes
Statistics
Notes
  • I have found many features Magento 1. x & Magento 2 extensions that will be useful for us. In that's are Advanced Newsletter Popup, Advanced Category Slider, Most Viewed & Sold Product Count, Size Chart, Our Services – Extension for Magento® 2 that I like the most. https://goo.gl/tRX8UD
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • there is an error in slide no :- 9
    correct url is :- http://localhost/magento/display/display/hello
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
18,161
On SlideShare
0
From Embeds
0
Number of Embeds
22
Actions
Shares
0
Downloads
148
Comments
2
Likes
4
Embeds 0
No embeds

No notes for slide

How to create a magento controller in magento extension

  1. 1. How to Create A Controller in Magento Extension Bippo CommerceCreating your own pages in Magento.
  2. 2. URL Structurehttp://demo.bippo.co.id/module/controller/action
  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_Display Controller extends Mage_Core_Controller_Front_Action{ public function showAction(){ }} Bippo/MyBanner/controllers/DisplayController.php
  6. 6. Router Config...<frontend> <routers> <mybanner> <use>standard</use> <args> <module>Bippo_MyBanner</module> <frontName>display</frontName> </args> </mybanner> </routers></frontend>... Bippo/MyBanner/etc/config.xml
  7. 7. "Raw" Action
  8. 8. Testpublic function helloAction(){    echo "Hello World";}
  9. 9. Test it http://localhost/magento/mybanner/display/hello
  10. 10. Layout-based Action
  11. 11. Layout Config<frontend> <layout> <updates> <mybanner> <file>mybanner.xml</file> </mybanner> </updates> </layout> </frontend> Bippo/MyBanner/etc/config.xml
  12. 12. 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
  13. 13. Load Layout in Actionpublic function smallAction(){ $this->loadLayout(); $this->renderLayout();}
  14. 14. Test /mybanner/display/small
  15. 15. Get URL from PHP<?php echo Mage::getUrl(mybanner/display/small) ? >
  16. 16. Process Input<form action="<?php echo Mage::getUrl(arithmetic/integer/multiply) ?>" method="post"> <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>
  17. 17. Is Form POST ?$this­>getRequest()­>isPost()
  18. 18. 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();}
  19. 19. Support Messages Block$this­>_initLayoutMessages(customer/session);Other choices: adminhtml/session catalog/session checkout/session
  20. 20. Add Message    Mage::getSingleton(customer/session)­ >addSuccess("$int1 * $int2 = $result");
  21. 21. Display Message in PHTML Templateecho $this­>getMessagesBlock()­>getGroupedHtml();
  22. 22. References http://blog.baobaz.com/en/blog/magento­module­create­your­own­controller

×