How to create a Magento module Z's Hello World example (RPM)

Source: Internet
Author: User
Tags blank page

Steps:
1. Create a Hello World module
2. Configure routing for this module
3. Create an execution controller for this module

Creating the Hello World module



To create a structure directory for a module:
App/core/local/sjolzy/helloworld/block
App/core/local/sjolzy/helloworld/controllers
App/core/local/sjolzy/helloworld/etc
App/core/local/sjolzy/helloworld/helper
App/core/local/sjolzy/helloworld/model
App/core/local/sjolzy/helloworld/sql
To create the content of CONFIG. App/core/local/sjolzy/helloworld/etc/config.xml:
<config>
<modules>
<Sjolzy_HelloWorld>
<version>0.1.0</version>
</Sjolzy_HelloWorld>
</modules>
</config>
Then create a system configuration file to activate this module
Sjolzy_helloworld.xml (App/etc/modules/sjolzy_helloworld.xml)
<config>
<modules>
<Sjolzy_HelloWorld>
<active>true</active>
<codePool>local</codePool>
</Sjolzy_HelloWorld>
</modules>
</config>
Check whether the module is activated: Empty the Magento Cache first (Var/cache), manage in the background: system->configuration->advanced expand disable Modules Output to see if Sjolzy _helloworld show up.

Configure Routing


Routing is used to convert a URL request into a method of executing a controller.
You need to explicitly define your route in the global configuration of Magento.
in CONFIG. app/core/local/sjolzy/helloworld/etc/config.xml:
<config>
...
<!--/* Fontend: The front desk to the website (or admin|install) */-
<frontend>
<!--/* Routers: Definition of route object or definition of routing path */-
<routers>
<!--/* HelloWorld: The front desk pointing to the website *-and
<use>standard</use>
<args>
<!--/* module: Lower-case version of the block name */-
<module>Sjolzy_HelloWorld</module>
<!--/* FontName: A parameter in the routing process that is only relevant to the route (Front controller is used to instantiate all routes) */-
<frontName>helloworld</frontName>
</args>
</routers>
</frontend>
</config>

To create an execution controller for a route


Routing will give control to the controller, we have defined the route, and now we define our execution controller.
App/code/local/sjolzy/helloworld/controllers/indexaction.php (the controller of the module is placed in the sub-directory controllers< lowercase >, which is the Magento rule)
<?php
Class Sjolzy_helloworld_indexcontroller extends mage_core_controller_front_action{
Public Function indexaction () {
Echo ' Hello world! ';
}
}
?>

Or the situation cache, request Url:http://example.com/helloworld/index/index
Note: http://example.com/frontName/execution controller/execution method


If you see a blank page that says ' Hello world! ', your module is created successfully!

How to create a Magento module Z's Hello World example (RPM)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.