Basic folder structure for new Magento Extension

Basic folder structure for new Magento Extension

When I had first contact with Magento platform, I had to create a custom module for it. I thought to myself – how hard can it be? How wrong I was… I didn’t even know where to start…

Anyway, as I already knew the principals of MVC (Model – View – Controller) architecture, and had fairly good knowledge of object orientated PHP, all I needed was the basic file/folder structure for my custom module.

Just a small notice before I start: there are numerous tutorials / blog posts that explain the contents of those files, and therefore I won’t go into that.

So, without any complications, I give you just that :D :


\app\code\local\MyNamespace

//If you're new to OOP, take a look here: http://www.php.net/manual/en/language.namespaces.rationale.php

\app\code\local\MyNamespace\Appname

//Name of new custom module - try to keep at least first letter capital, or there WILL BE truble with Magento's understanding

\app\code\local\MyNamespace\Appname\Block

//In classic MVC architecture, this represents View part of MVC

\app\code\local\MyNamespace\Appname\controllers

//This is fairly easy to understand, if not, have fun: http://en.wikipedia.org/wiki/Model%E2%80%93View%E2%80%93Controller

\app\code\local\MyNamespace\Appname \etc

//Contains the most significant part in Magento's MVC architecture - the xml field that will connect all things together

\app\code\local\MyNamespace\Appname\Helper

//Intended for files that contain repeatable routines or simple procedural methods

\app\code\local\MyNamespace\Appname\Model

//Same thing as for controller, take a look at the link above

\app\code\local\MyNamespace\Appname\sql

//This was interesting thing to find out what's it for, it's to define custom database tables and process any upgrades to your extension.

\etc\modules

//Contains all Modules included in Magento - here's where it all really begins for our module

And I just wanted to give you an idea of how things get connected here.

  1. Magento takes all xml files from “etc/modules/” to know which modules are there, and where are they located
  2. By that location (specified in xml file at “etc/modules/”) Magento includes xml file from “/app/code/local/MyNamespace/Appname/etc” so that it can connect all other things together
  3. The IndexController.php is the next one that’s included, and from there, it’s basic MVC (with slight variations)

I will provide 2 great tutorials that helped me a lot: ActiveCodeline tutorial and Magento Commerce tutorial

Well, I really hope this will help someone, because I know it would help me if I found it… :D

3
Top

Enjoyed this post?

Subscribe to our RSS Feed, Follow us on Twitter and spread it to your friends!

Author

Mladen Lotar

Ex. Inchooer

Mladen worked at Inchoo from 2010 to 2011 in the role of Magento/Zend developer

Other posts from this author

Discussion 3 Comments

Add Comment
  1. If you want to learn more about module configuration files, then checkout this article:
    http://www.ecomdev.org/2010/08/31/magento-module-configuration-file-reference.html

  2. Thanks for the article Mladen. That’s very helpful!

  3. @Ivan – thanks for the link, but check out the dates :D
    @Brady – thanks

Add Your Comment

Please wrap all source codes with [code][/code] tags.
Top