Magento Programming Basics
http://activecodeline.com/writing-a-custom-module-in-magento-detailed-walktroughMagento is a robust e-commerce solution built on the Zend Framework PHP platform. If you’re just starting out with Magento, you should familiarize yourself with XML, with programming PHP using an MVC framework (Zend Framework to be precise) and with the concept of design patterns. If you don’t understand those concepts, you don’t stand a chance in working with the code in Magento.
XML
XML stands for eXtensible Mark-up Language. It’s a set of rules for encoding data in documents electronically. If you were to open an XML document in a text editor, it strongly resembles HTML. Magento makes use of XML for all of it’s configuration files and layout files. Magento’s XML system is a layered one, so that when you add new modules, you can override the XML code from existing ones.
MVC (Model View Controller) and Zend Framework
Magento is built on Zend Framework, an MVC framework built in PHP. The core principle of MVC is to separate the code for the data, the rendering of the view and the control of the request.
- Controller – The Controller in an MVC app is the class that takes the request and decides how to process it. It uses Models to get data from a data source like a database and it uses Views to create the HTML that gets rendered by the user’s browser.
- SpinOneSolutions Part III, Controllers – An excellent article on Magento’s Controllers
- Model – The Model is the code in the application that handles requests to the database (or some other data source). The Model allows a user to encapsulate code that gives an object a particular behavior. For example, a Model for a Product would get the product’s price from the database. The other parts of the app (Controller and View) aren’t concerned with how the Model found the current price of the product.
- SpinOneSolutions Part II, Models – Once again, SpinOne has written a great article.
- SpinOneSolutions Part V, Data Model – Learn more about creating your own custom model.
- View – In an MVC application, the controller gives data to the view, and the view decides how the data gets rendered for the end user. The view might decide to take the data and create an RSS feed. It might make an HTML table with it. The view is the final step in creating output in a simple MVC process.
- Magento Designers Guide – This is the official guide for designers, with good explanations of Magento’s templating layers.
Design Patterns
Magento makes consistent use of design patterns. Design patterns is a programming concept that describes common methods to create reusable code. There are design patterns in PHP for Factories, Singletons, Observers and more. Magento uses design patterns throughout the codebase. Give yourself a jump start on learning design patterns by checking out Jack D Herrington’s article “Five Common PHP Design Patterns” and his follow up article “Five More PHP Design Patterns“. There are also many books on PHP Design Patterns, just check out Amazon.com.
Magento Modules
Magento’s entire structure is based on modules. Each of it’s modules provide specific functionality for various features. For example, there is a module called “Catalog” which provides the pages that allow users to browse your catalog of products. Magento’s developers are so committed to the module structure, they’ve built the entire core of Magento using modules. So the same technology you’re using the extend Magento was used to create it. Active Code Line has created a very good guide on how to create a Magento module from scratch.
Active Code Line Guide on How to Create Modules
