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 😀 :

\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… 😀

You made it all the way down here so you must have enjoyed this post! You may also like:

How I learned to stop worrying and love 3rd party modules for Magento Luka Rajcevic
Luka Rajcevic, | 2

How I learned to stop worrying and love 3rd party modules for Magento

Remind customers to place their first order in Magento Marko Martinovic
Marko Martinovic, | 17

Remind customers to place their first order in Magento

Per product meta robots tag control in Magento Marko Martinovic
Marko Martinovic, | 19

Per product meta robots tag control in Magento

5 comments

  1. Hello,

    I want to create my own extension. I need to add my JS file.

    Where I have to add JS file in skin folder?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

Tell us about your project

Drop us a line. We'd love to know more about your project.