Magento Expert Forum - Improve your Magento experience

Results 1 to 6 of 6

Magento Module Development - Part 1 - Get started

  1. #1
    Junior Member rocker's Avatar
    Join Date
    Mar 2013
    Posts
    105
    Thanks
    3
    Thanked 11 Times in 9 Posts

    Post Magento Module Development - Part 1 - Get started

    This is a basic hello world module, what will do is simple print “helloworld” on a magento page, using our custom module. As we have seen earlier, Magento modules follows, MVC pattern i.e. Model , View and Controllers. So in our module also we will have to create files following the MVC architecture.

    Before starting with the module we need to first decide the name of the module, because after creating a module it’s very difficult to change the name of the module.

    Module name usually comprises of 2 parts _ or it’s also called _. In our case I will take the name of module as Excellence_Test.

    First step is to create the folders and files for our module.

    First file we will create is Excellence_Test.xml file in location app/etc/modules/

    HTML Code:
    <?xml version="1.0"?>
    <config>
        <modules>
            <Excellence_Test>   <!-- Name of Module -->
                <active>true</active>  <!-- This says if the module is active or not -->
                <codePool>local</codePool> <!-- This says the location of the module i.e inside the local folder. It can also be community folder. -->
            </Excellence_Test>
        </modules>
    </config>
    This is a very important file, which tells magento about our module. Based on this file only, magento reads our module files. If in some case, you would want to disable the module, you can simple rename this file to some other name.

    Next go the folder app/code/local/ and then create folder structure as shown here

    Next we create the configuration file of the module: config.xml inside folder Excellence/Test/etc. So etc/config.xml is created

    HTML Code:
    <?xml version="1.0"?>
    <config>
        <modules>
            <Excellence_Test>
                <version>0.1.0</version>    <!-- Version of module -->
            </Excellence_Test>
        </modules>
        <frontend>
            <routers>
                <test>
                    <use>standard</use>
                    <args>
                        <module>Excellence_Test</module>
                        <frontName>test</frontName>  <!-- This is the URL
     of the module. i.e www.yourmagento.com/index.php/test will be the url of your module. -->
                    </args>
                </test>
            </routers>
        </frontend>
        <global>
            <blocks>
                <test>
                    <class>Excellence_Test_Block</class>  <!-- Path of the
     Block Folder, where all php files are located related to view -->
                </test>
            </blocks>
            <helpers>
                <test>
                    <class>Excellence_Test_Helper</class>  
    <!-- Path of Helper Files -->
                </test>
            </helpers>
        </global>
    </config>
    Next, we will create the Controller file. Controller files are used to manage between view and models. Controllers files are the first file to get executed when open a URL. Will explain URL and Controller relationship in detail later.

    Now lets create a file called IndexController.php.

    PHP Code:
    class Excellence_Test_IndexController extends Mage_Core_Controller_Front_Action
    {
        public function 
    indexAction()
        {
            echo 
    "Hello World";
        }

    Here are few important things to note:

    First is class name i.e Excellence_Test_IndexController

    In magento, class name depends on the folder location of the file.

    So for example the class Mage_Core_Controller_Front_Action, exists at location Mage/Core/Controller/Front/Action.php

    All controller file must extend Mage_Core_Controller_Front_Action to work properly

    Ok, now to test if the module work properly open the url www.your-magento.com/test/ this should display Hello World on the screen.

    Notes:

    When creating controller files or block file, etc remember to be careful about case sensitivity of file names. Especially, when you upload your module to linux server the module may stop working, if file cases and class name have not been put in carefully.

    All class names should be case-sensitive as well. Basically, based on the class name, magento includes that file. So, if class name is not correct, the file is not found by magento.

    If you’re module beginner, try to keep the module name CamelCased

    . If your choose module names like Excellence_TestReport this might create a problem. As you can see “TestReport” has two capital letter, so this sometimes creates the problem in linux server.

    It’s general good practice to keep all public functions in magento as CamelCased

    View more threads in the same category:


  2. #2
    New member mavencrux's Avatar
    Join Date
    May 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Magento Module Development

    Find useful Magento extensions and modules customized for your ecommerce online store. Complete Magento solutions for administration, checkout, customer service, online advertisement, product reviews, online store enhancement, discount shopping, shipping and logistics.

  3. #3
    Junior Member
    Join Date
    May 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    No doubt magento module is not easy to explain & teach but you have made it so easy.

  4. #4
    New member
    Join Date
    Sep 2013
    Location
    New York
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post

    Yes I think you have made it so easy. It is user friendly and make the things easy in comparison.









    7 seconds to make your first impression

  5. #5
    Junior Member
    Join Date
    Sep 2018
    Location
    United Kingdom
    Posts
    635
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default

    A module is a directory that contains the PHP and XML files (blocks, controllers, helpers, models) that are related to a specific business feature, such as Shipping. Specifically, a Magento module is composed of these software components: themes, libraries, and language packages

  6. #6
    Junior Member
    Join Date
    Sep 2018
    Location
    Oman, Muscat
    Posts
    2,084
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default

    format of Magento/Cms module. Every organizer holds one piece of the design, as follows: Setting up the Magento 2 Module Development Environment.

Similar Threads

  1. Magento Module Development - Part 9 - Collection and SQL
    By rocker in forum Programming & Development
    Replies: 9
    Last Post: 21-08-2018, 01:48 PM
  2. Magento Module Development - Part 6 - System.xml Advance and Module
    By rocker in forum Programming & Development
    Replies: 1
    Last Post: 29-05-2013, 12:10 PM
  3. Magento Module Development - Part 8 - Events
    By rocker in forum Programming & Development
    Replies: 0
    Last Post: 29-04-2013, 02:46 AM
  4. Magento Module Development - Part 7 - Overriding
    By rocker in forum Programming & Development
    Replies: 0
    Last Post: 29-04-2013, 02:37 AM
  5. Magento Module Development - Part 5 - System.xml and Module
    By rocker in forum Programming & Development
    Replies: 0
    Last Post: 29-04-2013, 02:25 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •