Magento’s base structure
The fundamental knowledge of Magento’s architecture begins with its file structure. It’s important to know what goes where by default, so that we may position our new files accordingly, especially in terms of ensuring that our development doesn’t overwrite core files.
The default installation contains the following files and directories in the base directory:
- 404 (directory)
- app (directory)
- downloader (directory)
- js (directory)
- lib (directory)
- media (directory)
- pkginfo (directory)
- report (directory)
- skin (directory)
- var (directory)
Each of these files and directories has a different purpose. We’ll go through them to ensure that we understand the function of each. This will help us later, if ever we need to find something specific, or when developing. It will also be helpful when we’ll be looking to place the files coming out of our new module into the appropriate directory.
The function of each of the files in the base directory
The following is a run through of all the files in the base directory, to show us what they do:
- .htaccess—This file controls mod_rewrite for fancy URLs and sets configuration server variables (such as memory limit) and PHP maximum execution time, so that Magento can run better.
- .htaccess.sample—Works as a backup for .htaccess, so that we know the default .htaccess file (if ever we edit it and need to backtrack).
- cron.php—The file that should be executed as a cron job every few minutes to ensure that Magento’s wide caching doesn’t affect our server’s performance.
- favicon.ico—Magento’s default favicon; it’s the small icon that appears in the toolbar of our browser.
- index.php—The main loader file for Magento and the file that initializes everything.
- index.php.sample—The base template for new index.php files, useful when we have edited the index.php file and need to backtrack.
- LICENSE_AFL.txt—It contains the Academic Free License that Magento is distributed under.
- LICENSE.txt—It contains the Open Software License that Magento is distributed under.
- pear—This controls all automatic updating via the downloader and SSH. This file is initialized and handles the updating of each individual module that makes up Magento.
- php.ini—A sample php.ini file for raw PHP server variables recommended when setting up Magento on our server. This should not be used as a complete replacement, but only as a guide to replace certain lines of the php.ini server file. It is useful when overriding these variables when .htaccess isn’t enabled on our server.
The function of each of the folders in the base directory
The following is a run through of all the folders in the base directory to show us their contents:
- 404—The default 404 template and skin storage folder for Magento.
- app—All code (modules), design (themes), configuration, and translation files are stored in this directory. This is the folder that we’ll be working in extensively, when developing a Magento powered website. Also contained in this folder are the template files for the default administration theme and installation.
- downloader—The web downloader for upgrading and installing Magento without the use of SSH.
- lib—All PHP libraries used to put together Magento. This is the core code of Magento that ties everything together. The Zend Framework is also stored within this directory.
- media—All media is stored here. Primarily for images out of the box, this is where all generated thumbnails and uploaded product images will be stored. It is also the container for importing images, when using the mass import/export tools.
- pkginfo—Short form of package information, this directory contains text files that largely operate as debug files to inform us about changes when modules are upgraded in any way.
- report—The skin folder for the reports that Magento outputs when any error occurs.
- var—Typically where we will find all cache and generated files for Magento. We can find the cache, sessions (if storing as files), data exports, database backups, and cached error reports in this folder.
The template system architecture
The template architecture is broken into three areas—two for development of the theme and one for the containment of the assets:
- layout/—For all the XML files declaring which module tied functions should be called to which template files
- template/—For all the templates processing the output that is passed from functions called from layout/ and structured into the final output to the user.
Structural blocks and content blocks
Each theme contains structural and content blocks. Structural blocks are the ones that lay out the theme into sections. Let’s take a look at a three-column layout. The following are the structural blocks in a three-column layout:
Here’s a visual representation of those structural blocks laid over the Magento demo store:
In each of the structural blocks, we then have content blocks that give each structural block its content for output to the browser. Let’s take the right column; our content blocks set for this column on a standard theme could be:
- mini cart
- recently viewed products
- newsletter subscription block