Start by creating your module:

1 – Create the folder /app/code/local/Pfay/Test/

This create your namespace Pfay and your module Test .

2 – Enable the module in Magento:

Add a file Pfay_all.xml /app/etc/module/

And insert the following code in it

1 2 3 4 5 6 7 8 9 <? xml version = "1.0" ?> < config > < modules > < Pfay_Test > < active > true </ active > < codePool > local </ codePool > </ Pfay_Test > </ modules > </ config >

This file is used to declare all your modules in the Pfay namespace, you have to put it between the tags « modules » declaration of your plugin one after the other.

1 2 3 4 < Pfay_Test > < active > true </ active > < codePool > local </ codePool > </ Pfay_Test >

Pfay_Test allows you to declare the namespace of your plugin Test Pfay.

active: true = the plugin is active

false = the plugin is not enabled

codePool: The module will be in the local file because it is a module that we create ourselves (remember the lesson 1).

Magento will therefore find the files in that module in the /app/code/ local/Pfay/Test/

ahead and create the controller:

go to /app/code/local/Pfay/Test/

1 – Create the file /app/code/local/Pfay/Test/controllers/

2 – Inside create a IndexController.php which will contain:

1 2 3 4 5 6 7 8 9 10 11 class Pfay_Test_IndexController extends Mage_Core_Controller_Front_Action { public function indexAction () { echo 'test index' ; } public function mamethodeAction () { echo 'test mymethod' ; } }

Now if you go to http://yoursite.com/test/index, What’s happening?

Actually … you can not find the page, there’s an error because you have not already declare your controller in the plugin.

Config.xml file to configure your plugin:

In the same way that you have declared your plugin for Magento to take into account Pfay_All.xml, the file config.xml of your plugin will allow you to you declare the controller of your plugin.

Mangento will check Pfay_All.xml and find your file, it will go in your /app/code/local/Pfay/Test/etc/ and reads the config.xml file to see or pick up your controller.

So create your file Test , a record etc/ with in config.xml .

config.xml contains:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 <? xml version = "1.0" ?> < config > < modules > < Pfay_Test > < version >1.0.0</ version > </ Pfay_Test > </ modules > < frontend > < routers > < routeurfrontend > < use >standard</ use > < args > < module >Pfay_Test</ module > < frontName >test</ frontName > </ args > </ routeurfrontend > </ routers > </ frontend > </ config >

Explanation:

1 2 3 4 5 < modules > < Pfay_Test > < version >1.0.0</ version > </ Pfay_Test > </ modules >

In this section, we declare the identity of the module for magento module to verify that what you declare in your Pfay_All.xml is the good plugin and if the version number allow you to eventually have an update for your plugin.

1 2 3 4 5 6 7 8 9 < routers > < routeurfrontend > < use >standard</ use > < args > < module >Pfay_Test</ module > < frontName >test</ frontName > </ args > </ routeurfrontend > </ routers >

Allows you to declare a router « routeurfrontend » which is actually the road used by magento to access your controller.

In our example, the router is « standard » (it means that it is a module that will be displayed on the frontend).

The module name is Pfay_Test and the shortcut to access it via the url is test and when you will type

http://yoursite.com/test/index, we arrive on the index method of your controller IndexController.php (in your folder controllers )

You can also access it using your router in place of frontName.

http://yoursite.com/routeurfrontend/index/

Now test your module:

http://yoursite.com/test/index, you can read « test index » (you can add /index at the end of your url if you want to call the index method but by default if nothing is specified it calls the method « index »)

You know now create a controller. Now try to understand this by doing it again and again at home and you should be able to move on the next tutorial.

If you have any questions, feel free to leave a comment. If you want to help me, share a link to this website with your friends on facebook, twitter etc…