官术网_书友最值得收藏!

Code pools

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:

  • Choose the community codePool for extensions that you plan to share across projects, or possibly upload to Magento Connect
  • Choose the local codePool for extensions that are specific for the project you are working on and won't be shared with the public

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 the Mage_Core_Block_Template class from within the app/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 the app/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 the Mage_Core_Controller_Front_Action class from within the app/code/core/Mage/Core/Controller/Front/Action.php file or the Mage_Adminhtml_Controller_Action class from within the app/code/core/Mage/Adminhtml/Controller/Action.php file.
  • etc: This folder contains various XML configuration files such as adminhtml.xml, api.xml, config.xml, system.xml, wsdl.xml, wsdl2.xml, and wsi.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 the Mage_Core_Helper_Abstract class from within the app/code/core/Mage/Core/Helper/Abstract.php file. The Helper 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.

主站蜘蛛池模板: 清水县| 天气| 绥德县| 桐城市| 普兰店市| 分宜县| 富裕县| 米林县| 从江县| 宿松县| 永平县| 岳阳县| 酒泉市| 石渠县| 行唐县| 邛崃市| 张家口市| 巩义市| 宜兰县| 台北县| 大安市| 潼关县| 宜黄县| 拜城县| 孙吴县| 邹平县| 汶川县| 天津市| 宁国市| 罗江县| 惠来县| 同德县| 遵化市| 彰化市| 姜堰市| 牡丹江市| 蓬莱市| 辽中县| 牙克石市| 杭锦后旗| 辛集市|