I've looked and looked on google, but can't find a single site explaining what each of the 6 module subfolders are. I'm usually really good at finding things on google, but this one has constantly come up with nothing.
Could someone explain the differences between each of the subfolders in a Magento module (Block, controllers, etc, Helper, Model, sql)?
In a very small nutshell:
Block are responsible for rendering content (everything from frontend, backend, emails, and more). If content is being displayed somewhere chances are it is a block.
controllers are responsible for processing all requests made via a url. If you hit the url http://www.example.com/catalog/product/view/id/9/ you hit the catalog module in the controllers/ProductController.php and inside of that the viewAction() method. If you hit a URL in Magento the request passes through one or more controllers.
etc contains any configuration xml files for the modules. These are responsible for everything from ACL (access control lists) to how to access blocks/models etc to system configuration settings. Some sample files:
Helper - These files are "helpers". They contain functions that are common to the module or that may be accessed by other modules. One functionality of these is to provide translations. In addition, Data.php is the default helper that is included here. If you have system configurations a Data.php is required for the system configuration to appear correctly.
Model - These are your objects of data. For example a Product or Category is a model. They provide data management functions. They interface with a Resource folder contained in the model folder to access the database, and Collections to get a collection of objects.
sql - These are your setup scripts. When a module is installed if configured correctly some changes might need to be made to the database: adding tables, attributes to products, or custom configurations.
I recommend taking a look at http://alanstorm.com/category/magento
He has many samples, tutorials, and other good tips and is a more complete starting place.
The best way to understand each functionality is to take a look at a module in core.
Helpers - Magento's Helper classes contain utility methods that will allow you to perform common tasks on objects and variables. For example: $helper = Mage::helper('catalog')
Blocks - Each Block object will render a specific bit of HTML. Block objects do this through a combination of PHP code, and including PHP .phtml template files. Blocks objects are meant to interact with the Magento system to retrieve data from Models, while the phtml template files will produce the HTML needed for a page
controllers - In any PHP system, the main PHP entry point remains a PHP file. Magento is no different, and that file is index.php.
Magento Models - Magento, like most frameworks these days, offers an Object Relational Mapping (ORM) system. ORMs get you out of the business of writing SQL and allow you to manipulate a datastore purely through PHP code (and other core business logics)
etc - This is where you put your config files (config.xml, system.xml and/or adminhtml.xml), to tell magento what your module have access to and other config about your custom module (see example)
sql - This is where you put your setup script (e.g. add a new table to your magento db)
Take a look @ Magento for Developers: Part 1 - Introduction to Magento
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With