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.
- Magento takes all xml files from “etc/modules/” to know which modules are there, and where are they located
- 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
- The IndexController.php is the next one that’s included, and from there, it’s basic MVC (with slight variations)
Well, I really hope this will help someone, because I know it would help me if I found it… 😀