php - Magento 1.9 create new Hello World module -


hello, guys!

i hope me this.
trying make new module in magento 1.9.3.2, show "hello world!" phtml file. created step step rules. module created, when open module (127.0.0.1/magento/helloworld) in browser, nothing appear, empty template. opened module in browser - screenshot

here steps guided:
1. module declaration: create new xml file in app/etc/modules/m4u_helloworld.xml
<?xml version="1.0"?> <config> <modules> <m4u_helloworld> <active>true</active> <codepool>local</codepool> </m4u_helloworld> </modules> </config>

  1. module configuration
    2.1. create controller class in app/code/local/m4u/helloworld/controllers/indexcontroller.php

    class m4u_helloworld_indexcontroller extends mage_core_controller_front_action { public function indexaction() { $this->loadlayout(array('default')); $this->renderlayout(); } }

2.2. create block class in app/code/local/m4u/helloworld/block/helloworld.php

class m4u_helloworld_block_helloworld extends mage_core_block_template                   {                        // necessary methods                   } 

2.3. create configuration xml in app/code/local/m4u/helloworld/etc/config.xml

<?xml version="1.0"?> <config> <global>     <modules>             <m4u_helloworld>                     <version>0.1.0</version>             </m4u_helloworld>     </modules> <blocks>         <helloworld>             <rewrite>      <helloworld>m4u_helloworld_block_helloworld</helloworld>     </rewrite>         </helloworld>  </blocks>     </global>    <frontend>             <routers>                     <helloworld>                             <use>standard</use>                             <args>                                   <module>m4u_helloworld</module>                                   <frontname>helloworld</frontname>                             </args>                     </helloworld>             </routers>     <layout>         <updates>             <helloworld>                   <file>helloworld.xml</file>             </helloworld>         </updates>         </layout>     </frontend> 

  1. define frontend template
    3.1. define page layout in app/design/frontend/default/default/layout/helloworld.xml
    <?xml version="1.0"?> <layout version="0.1.0"> <helloworld_index_index> <reference name="root"> <action method="settemplate"> <template>page/1column.phtml</template></action> </reference> <reference name="content"> <block type="helloworld/helloworld" name="hello" template="helloworld/helloworld.phtml"/> </reference> </helloworld_index_index> </layout>

  2. create template file in app/design/frontend/default/default/template/helloworld/helloworld.phtml

tried , tested

screenshot here

you can display helloworld template in custom module, done minor modifications code.

  1. module declaration:

    <?xml version="1.0"?>  <config>        <modules>           <m4u_helloworld>                <active>true</active>                <codepool>local</codepool>           </m4u_helloworld>        </modules>  </config> 
  2. creating folder structure , add files

a. app/code/local/m4u/helloworld/etc/config.xml

<config>     <modules>         <m4u_helloworld>             <version>0.1.0</version>         </m4u_helloworld>     </modules>     <frontend>         <routers>             <helloworld>                 <use>standard</use>                 <args>                     <module>m4u_helloworld</module>                     <frontname>helloworld</frontname>                 </args>             </helloworld>         </routers>         <layout>             <updates>                 <helloworld module="m4u_helloworld">                     <file>m4u_helloworld.xml</file>                 </helloworld>             </updates>         </layout>     </frontend>     <global>         <blocks>             <helloworld>                 <class>m4u_helloworld_block</class>             </helloworld>         </blocks>     </global> </config> 

b. app/code/local/m4u/helloworld/block/helloworld.php

class m4u_helloworld_block_helloworld extends mage_core_block_template {  } 

c. app/code/local/m4u/helloworld/controllers/indexcontroller.php

class m4u_helloworld_indexcontroller extends mage_core_controller_front_action {      public function indexaction() {         echo 'hello world';         $this->loadlayout();  //this function read layout files , loads them in memory         $this->renderlayout();     }  } 

d. app/design/frontend/ * theme base* / * mytheme * /layout/m4u_helloworld.xml

<?xml version="1.0" encoding="utf-8"?> <layout version="0.1.0">     <helloworld_index_index>         <reference name="root">             <action method="settemplate">                                   <template>page/1column.phtml</template>             </action>         </reference>         <reference name="content">             <block type="helloworld/helloworld" name="hello" template="helloworld/helloworld.phtml"/>         </reference>     </helloworld_index_index> </layout> 

e. app/design/frontend/ * theme base* / * mytheme * /template/helloworld/helloworld.php

echo 'im template block'; 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -