magento如何创建一个模块,
目录结构
magento模块一般放在app/code/local/Packagename
中,PackageName一般指包名,相当于一个大类。
app/code/local/test
我们在做一个产品订阅的模块,首先,创建模块,我们需要创建以下所示的目录结构。
app/code/local/Test/Subscribe/Block
app/code/local/Test/Subscribe/controllers
app/code/local/Test/Subscribe/etc
app/code/local/Test/Subscribe/Helper
app/code/local/Test/Subscribe/Model
app/code/local/Test/Subscribe/sql
一个模块并不一定需上述所有的目录。
配置文件
当然仅仅创建上面的目录文件,magento并不会认为这是一个模块。
需要创建两个配置文件,一个在etc目录下。这个是配置这个模块的各种信息。
app/code/local/test/Subscribe/etc/config.xml
第2个是位于下面路径,是告诉magento这个模块的存在。
app/etc/modules/Test_Subscribe.xml
其中config.xml文件中会包含下面的代码。
<config>
<modules>
<Test_Subscribe>
<version>0.1.0</version>
</Test_Subscribe>
</modules>
</config>
Test_Subscribe.xml中需要包含一下配置文件代码
<config>
<modules>
<Test_Subscribe>
<active>true</active>
<codePool>local</codePool>
</Test_Subscribe>
</modules>
</config>
这样你就创建了一个基本的模块,magento已经能够识别此模块的存在。
登录Magento后台,进行如下操作,
•清空Magento缓存
•访问System->Configuration->Advanced
•点击”Disable modules output”,大概在最下面的位置,能够找到你刚创建的模块