The folder code
is a placeholder for what is called a codePool in Magento. Usually, there are three code pools in Magento, that is, three subfolders: community
, core
, and local
.
The folder local
is sometimes missing from the downloaded installation archive, as it is empty by default.
Let's take a deeper look at the community codePool for the default Magento installation as shown in the following diagram:
community/ └── Phoenix └── Moneybookers ├── Block │ ├── Form.php │ ├── ... │ └── Redirect.php ├── Helper │ └── Data.php ├── Model │ ├── Abstract.php │ ├── ... │ └── Wlt.php ├── controllers │ ├── MoneybookersController.php │ └── ProcessingController.php ├── etc │ ├── config.xml │ └── system.xml └── sql └── moneybookers_setup ├── install-1.6.0.0.php └── mysql4-upgrade-1.2-1.2.0.1.php
Here, the Phoenix
folder is what is called the vendor namespace, and it usually matches your company identifier or something else unique to you. Within the Phoenix
folder there is a Moneybookers
subfolder that stands for your actual extension name.
To summarize, the formula for your extension code location should be something like app/code/community/YourNamespace/YourModuleName/
or app/code/local/YourNamespace/YourModuleName/
.
There is a simple rule as to whether to choose community
or local
codePool
:
For example, let's imagine that our company name is Foggyline
and the extension we are building is called Happy Hour
. As we wish to share our extension with the community, we can put it into a folder such as app/code/community/Foggyline/HappyHour/
.
All the Magento core code is also divided into extensions, and is located under the app/code/core/Mage
folder. You should never place any of your code or edit any of the existing code under the app/code/core
folder.
Let us get back to our example from the previous listing, the Moneybookers
extension. We can see that it has several subfolders within it:
Block
: This folder contains various PHP classes. You can think of the Block folder as a placeholder for class objects that visually manifest themselves to the user on a frontend. Most of these PHP classes extend theMage_Core_Block_Template
class from within theapp/code/core/Mage/Core/Block/Template.php
file. These PHP classes are then linked to various layouts and template*.phtml
files within the given theme under theapp/design
folder.controllers
: This folder contains various PHP classes. You can think of controllers as a glue between our URL actions, models, blocks, and views. Most of these classes extend theMage_Core_Controller_Front_Action
class from within theapp/code/core/Mage/Core/Controller/Front/Action.php
file or theMage_Adminhtml_Controller_Action
class from within theapp/code/core/Mage/Adminhtml/Controller/Action.php
file.etc
: This folder contains various XML configuration files such asadminhtml.xml
,api.xml
,config.xml
,system.xml
,wsdl.xml
,wsdl2.xml
, andwsi.xml
. Depending on what type of extension you are building, you might find some configuration files used more than the others.Helper
: This folder contains various PHP classes, most of which extend theMage_Core_Helper_Abstract
class from within theapp/code/core/Mage/Core/Helper/Abstract.php
file. TheHelper
classes contain various utility methods that will allow you to perform common tasks.Model
: This folder contains various PHP classes that usually, but not necessarily, represent an entity in a database. This is the folder where you would place most of your business logic.sql
: This folder contains one or more PHP files representing the installer code to be executed during the installation of the extension.
With that said, we will temporarily conclude our trip to the app/code
folder structure and move on to the app/etc/modules
folder.
This folder is basically a starting point for every Magento extension. The following listing shows the default content of the app/etc/modules
folder for the default Magento installation, which is a collection of XML files:
Mage_All.xml
Mage_Downloadable.xml
Mage_Api.xml
Mage_ImportExport.xml
Mage_Api2.xml
Mage_Oauth.xml
Mage_Authorizenet.xml
Mage_PageCache.xml
Mage_Bundle.xml
Mage_Persistent.xml
Mage_Captcha.xml
Mage_Weee.xml
Mage_Centinel.xml
Mage_Widget.xml
Mage_Compiler.xml
Mage_XmlConnect.xml
Mage_Connect.xml
Phoenix_Moneybookers.xml
Mage_CurrencySymbol.xml
For example, if we were to create our Foggyline/Happy Hour
extension, we would need to create a file app/etc/modules/Foggyline_HappyHour.xml
as we will show later on.
Next, we move onto the app/local
folder. This is where the translation files reside. If you were building an extension that would support multiple languages, for example English and German, you might want to create the following files:
app/locale/en_US/Foggyline_HappyHour.csv
app/locale/de_DE/Foggyline_HappyHour.csv
The exact filename in this case does not have to be Foggyline_HappyHour.csv
; this is something that is set by you within the extension configuration.