Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create module in magento ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 106
    Comment on it

    Before we create magento custom module, let’s have a look on code directory structure of magento where we create custom module. Here is only code folder structure.

    - app (contains code pools, design, configuration, localization and Mage.php files)

            - code (contains the code files)

                             - community (third party modules)

                             - core (magento core modules)

                             - local (local modules)

    local folder contain namespace folder-> module folder(custom module)

     

    components of Module :

    (these all components are folder/directory under Module folder):
    Blocks:  contain functions that are used to display data in templates.
    Models: define business logic of modules.
    Controllers: Defines page layout and blocks files Which are loaded when a URL is Hit by user.
    etc:  contains configuration files which tells magento how the module interacts.
    Helpers: contain functions like image resize & validation etc which can be used anywhere in our application
    sql:  contains SQL scripts to create, modify, or delete SQL tables.

     

    How to create custom module in magento ?

    step 1:
    Go to app/code/local/ & create folder pankaj/Mymodule/etc,

    in etc folder, create a config.xml file with the following code.

    <?xml version="1.0"?>
    <config>
        <modules>
            <Pankaj_Mymodule>
                <version>0.1.0</version>
            </Pankaj_Mymodule>
        </modules>
        <frontend>  //tell Magento about the controller dispatched.
            <routers> //tells Magento how to access our controllers
                <mymodule>// tells magento how to access our module in frontend
                    <use>standard</use>
                    <args>
                        <module>Pankaj_Mymodule</module>
                        <frontName>mymodule</frontName>
                    </args>
                </mymodule>
            </routers>
        </frontend>
    </config>

     

    step 2:
    Go to  app/code/local/pankaj/Mymodule & create controllers folder.
    in controllers folder, ctreat IndexController.php with following code

    <?php
    class Pankaj_Mymodule_IndexController extends Mage_Core_Controller_Front_Action
    {
        public function indexAction()
        {
            echo "Hello there";
        }
    }
    
    ?>

     

    Next step is activate our module by creating config file Pankaj_Mymodule.xml in the app/etc/modules directory.

    <?xml version="1.0"?>
    <config>
        <modules>
            <Pankaj_Mymodule>
            <active>true</active>
            <codePool>local</codePool>
            </Pankaj_Mymodule>
        </modules>
    </config>


    This xml in etc tells magento that module is active and will be available in local codePool.

     

    how to Check: Is the module enabled?
    you can see your module in Magento Admin Panel.

    Go to System->Configuration->Advanced->Disable Modules Output.
    & You will come to know that Pankaj_Mymodule is there in the list of modules.

     

    Now open URL: if you are using localhost, then url is:  localhost/projectname/index.php/mymodule/index, it will print "Hello there".

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: