Part 3
1. Magento directory structure
/app : 是包含所有PHP文件代码的文件夹
/code : 是所有模块的位置
/community : 通常包含由社区使用Magento的核心团队开发的免费模块
/core : Magento内置的核心模块
/local : 通常包含自己建立的模块
/design : 设计包的位置(布局、模板、翻译)
/adminhtml :包含所有的adminhtml design
/frontend : 包含所有的frontend designs
/default : 默认接口
/layout : 包含所有布局文件
/template : 包含模板文件
/etc : 包含全局配置文件
/modules : 包含激活模块的配置文件
/locale : 包含不同的语言包
/local(en_US) : 包含CSV语言文件
/email : 由电子邮件模板文件组成(HTML)
/includes
/lib : Magento 的库文件(Zend varien)
/js:包含 Js 文件
/media : 由图像库,媒体组成
/var : includes files of template ,cache ,import ,export and log(包含模板,
缓存,导入,导出和日志的文件)
/skin : 包含 css 文件和图片
/adminhtml :contains css files and images of admin
/frontend : contains css files and images of frontend
/default : 默认的接口package
/default : 默认主题
/css : 默认主题的 css 文件
/images: 图片文件
/js : js 文件
2. The structure of module
Block :
monitors the template system in Magento. The code in block is used to load
database and display of template. This is also the location to
edit database if necessary
before showing it on the template. The display of which template
will be declared in the layout file:
在Magento中控制模板系统。在block中的代码被用来加载
数据库和模板显示。如果需要,该位置可以在模板上显示它之前
编辑数据库。模板的显示声明在布局文件中:
app/design/frontend/default/default/layout/your_module.xml.
例如:
<yourmodule_yourcontroller_youraction>
<reference name="content">
<block type="yourmodule/yourblock" name="your_name" template=
"yourmodule/yourtemplate.phtml"/>
</reference>
</yourmodule_yourcontroller_youraction>
When clients access the link: http://domain.com/yourmodule/index/index,
Magento will analyze this URL to find out names of module, controller
and action which are called out.
And then, it will search in layout
files to view the template which will be
used to display.
当客户访问链接:http://domain.com/yourmodule/index/index,Magento
将分析这个网址,以找出名称的模块,控制器和行动,并调用。
然后,它将搜索布局文件,以观察模板,这将是
用于显示。
Here is the file yourmodule/yourtemplate.phtml.
这里的文件yourmodule / yourtemplate.phtml。
etc:
contains XML files which are used to configure each module. There are three
important files:
包含用于配置每个模块的文件。有三
重要文件:
* Config.xml: directly configures module and declares
Module, Resource, Block, and
Helper…
config.xml:直接配置模块和声明模块,资源,块,和
助手…
* System.xml: configures default value and display in admin menu.
System.xml:配置默认值并显示在后台菜单
* Adminhtml.xml: creates menu in admin.
Adminhtml.xml: 在后台创建菜单
Model:
handles the process of the database access. Magento designs database
according to the EAV model so the database access is quite complicated.
This is the place to write functions which directly carry out queries.
Model:处理数据库访问的过程。Magento 根据EAV模型设计数据库,所以数据库访问是很复杂的。
这是编写直接进行查询的功能的地方。
Controllers: define process to execute request of users.
Controllers are classes which inherit from the basic
one:Mage_core_Controller_Varien_Action (inherits from class
Zend_Controller_Action).
Controllers:定义过程来处理请求的用户。控制器类
从基本mage_core_controller_varien_action(继承类
继承:zend_controller_action)。
Helper: you can add functions here in order
to do anything as you wish. To call one
function (Ex: helper Test) in Helper, you need to use the command below:
Mage::helper(‘yourmodule/yourhelp’)->helperTest();
Helper:您可以在这里添加功能,以做任何您想做的事。在助手
调用功能(例如:辅助测试),您需要使用以下命令:
Mage::helper('yourmodule /yourhelp”)-> helpertest();
sql: contains files to setup database for module which interact
with database (create table, update tables…)
sql:包含与数据库交互的设置数据库的文件(创建
表,更新表……)
•Besides, there are layout and template files for admin and frontend in the
folder: app/design/adminhtml/default/default and
app/design/frontend/default/default.
To declare Magento a new module you need to create a XML
file Yournamespace_Yourmodule.xml
Part 4
1. Create and register a module
In mounting a module in the operation of the system, the system first has
to be aware of the presence of that
module. Magento System will recognize
the existence of the module by reading all the *. Xml file in
the / app / etc / modules
在一个操作系统中安装模块,系统首先要感知的是
该模块的存在。Magento系统将通过读取所有*。文件在
/ app / etc / modules识别出的模块存在
A configured file Magestore_Test.xml to register operation of a
new module has the following form:
配置一个新的文件magestore_test.xml模块的注册操作
有如下形式:
<?xml version="1.0"?>
<config>
<modules>
<Magestore_Test>
<active>true</active>
<codePool>local</codePool>
</Magestore_Test>
</modules>
</config>
-Magestore_Test : Name of module(模块的名字)
-active : whether configuration of module operate or not (true/false)
(模块的配置与否)
-codePool: local => module này du?c d?t t?i thu m?c /app/code/local
(模块的位置)
2. Specify option in the config file (在配置文件中指定选项)
After loading the list of modules, system will find file config.xml
in folder module
((app/code/(codepool)/(NameSpace)/(ModuleName)/etc/config.xml)
to read operation configuration for this module. All configurations
are installed in <config></config>:
加载列表的模块后,系统会在模块文件夹
((app/code/(codepool)/(NameSpace)/(ModuleName)/etc/config.xml)
找到config.xml文件,读取操作。所有配置都安装在<config></config>中:
-modules: module configuration as active, depends, version
-modules: 模块配置为active, depends, version
-global: main configuration for models, resources, blocks, helpers,
fieldsets, template,events,
eav_attributes, custom_variables.
These configurations in this part
include basic configs for module,
configs about folders containing
or events (frontend and admin),
configures for email template.
-global:主要配置models, resources, blocks, helpers, fieldsets,
template,events, eav_attributes, custom_variables。
这部分的配置包括:模块的基本配置,关于含模型文件类文件夹的配置,model, block,helper
or events (frontend and admin), 配置电子邮件模板。
admin: containing configures attributes, fieldsets, routers.
In this config, we often
notice to configure for router of admin.fig.
admin: 包含配置attributes, fieldsets, routers。在这个配置中,我们经常注意配置
admin 的路由器。
-adminhtml: including configure operation of module in admin. The cards
in this part
often have layout, translate, events. These configures only have impact
on backend in Magento.
-adminhtml: 包括admin 模块的配置操作管理。这部分的卡片经常有
layout, translate, events.。
这些配置只影响Magento的后台。
-frontend: including configure operation of module on frontend such as cards:
secure_url, events,routers, translate, layout. The configurations
only have impact on frontend.
-frontend: 包括前端模块配置操作,如下:
secure_url, events,routers, translate, layout。
这些配置只影响前台。
-default: including configures of module for all stores
-default: 包括所有商店的模块配置
-stores: including configures for each store. In the card store is
<store_code> of each store.
-stores: 包括每个商店的模块配置。在<store_code>中配置每个商店。
-websites: including configure for each website. In card website
is <website_code>of each website.
-websites: 为每个网站配置。在<website_code>为
每个网站配置。
-Operate website/stores/stores views
Configure as configure xml to control websites/stores/stores
view is put on value table
in cards default, stores and websites.
<default>
<carriers>
<flatrate>
<active>1</active>
<sallowspecific>0</sallowspecific>
<price>5.00</price>
</flatrate>
</carriers>
</default>
Configure will have impact on all websites/stores in Magento.
However, when we
want to have different configure for websites or single store,
we can configure as below:
配置将影响Magento所有websites/stores。然而,当我们
想为网站或单一商店有不同的配置为,我们可以配置为
下面:
<websites>
<base>
<carriers>
<flatrate>
<active>1</active>
<sallowspecific>0</sallowspecific>
<price>5.00</price>
</flatrate>
</carriers>
</base>
</websites>
<store>
<english>
<carriers>
<flatrate>
<active>1</active>
<sallowspecific>0</sallowspecific>
<price>5.00</price>
</flatrate>
</carriers>
</english>
</store>
Changes to these values are made by administrator; we put all values in file
system.xml. In system, we will find configures by clicking in menu:
System->Configuration.
更改这些值是由管理员来做的,我们把所有的值都放在
system.xml文件里了。在系统中,点击菜单System->Configuration 我们会发现配置:。
Q:When we configure in menu System -> Configuration,
Advance and choose disable
module output, does module operate?
当我们在菜单System -> ConfigurationAdvance and choose disable module output,
模块将如何操作模块输出,模块运行?
A:When we disable module in menu Disable module output, all functions of
module still
operate normally, except for giving layout of blocks in module.
Because block of
Magento rendered to html will have this condition:
当我们禁用模块在menu Disable module output,所有功能模块仍然操作正常,
except for giving layout of blocks
in module.。因为Magento的块渲染成HTML会有这种情况:
final public function toHtml()
{
Mage::dispatchEvent('core_block_abstract_to_html_before',array('block'=>$this));
if(Mage::getStoreConfig('advanced/modules_disable_output/'.$this->getModuleName()))
{
return '';
}
}