Getting Started in magento with simple Helloworld example

By

March 22, 2012MagentoNo comments

A Helloworld module is the most needed article for every developer who needs to get into magento development. Initially when we started writing articles about magento there were many articles available already about this topic. Though it is little bit late i think it would be useful too, please feel free to write your comments about this.

In Todays article we will see how to write a very basic bare bone module in magento MVC. For easy understanding I skipped a few parts like creating block class and helper class.

Step 1: Lets first start with our module activation file Mydons_Helloworld.xml. It specifies module name, active status, and Directory the module exists.
The Activation xml file needs to be placed in app/etc/modules/ directory

Step 2: Now we need to create our module folders in app/code/local path as show below. Here Mydons is a Namespace for our module and Helloworld is our modulename

app/code/local/Mydons/Helloworld/etc/ – The etc directory is for creating our module configuration file

app/code/local/Mydons/Helloworld/controllers/ – The controllers directory is for creating our frontend controllers.

Step 3: The first thing we need to start when creating a module is to write the config.xml file. In the config file we need to specify our modulename, controllers, helper classes and block classes. For our example we dont need the Block class.

Step 4: Now lets create our view files. A View Layer in magento is further subdivided into

Block – A Block is a PHP Class the provides some methods calls to be called from the template phtml file. Purpose of Block Class is to separate things. A Block in turn will interact with a Model class to fetch some dynamic data and pass to the pthml file. A pthml file or template html file should not directly call model class and queries its main purpose should be to just display the data.

A Block class is not needed for a simple template like this example, so our template file
will make use of the already available base Block class in core module(Mage_Core_Block_Template).

– – layout – layout xml file provides the page layout, we can specify the block classs,template file to be displayed and Layout of the page (1col,2coletc)
template – Contains Just the data to be displayed.

Design files need to be placed in app/desing/frontend/default/default directory

Our layout xml file looks as shown below with path: app/design/frontend/default/default/layout/helloworld.xml

Our template file looks as shown below path: app/design/frontend/default/default/template/mydons/helloworld.phtml

<?php echo Mage::helper(‘core’)->__(‘Mydons Helloworld’) ?>

A Simple Helloworld Module example with Template file from Mydons

Step 5: So our final step is to call our view layer from the frontend controller. Here the controllers calls our block defined in the layout xml file.

Our final output:

Leave a Reply