Magento 1 创建简单模块

直接上代码吧。

必不可少的是 app/etc/modules/MyCompany_MyModule.xmlapp/code/local/MyCompany/MyModule/etc/config.xml

File: app/etc/modules/ThankIT_Devtool.xml

<?xml version="1.0"?>
<config>
    <modules>
        <ThankIT_Devtool>
            <active>true</active>
            <codePool>local</codePool>
        </ThankIT_Devtool>
    </modules>
</config>

File:app/code/local/ThankIT/Devtool/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <ThankIT_Devtool>
            <version>0.1.0</version>
        </ThankIT_Devtool>
    </modules>
     <frontend>
        <routers>
            <thankit_SomeFreeRouterName1>
                <use>standard</use>
                <args>
                    <module>ThankIT_Devtool</module>
                    <frontName>dev</frontName>
                </args>
            </thankit_SomeFreeRouterName1>
        </routers>
    </frontend>
</config>

File: app/code/local/ThankIT/Devtool/controllers/IndexController.php

<?php

class ThankIT_Devtool_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        echo 'Hello developer...';
    }
    public function sayHelloAction()
    {
        echo 'Hello one more time...';
    }
}

下面访问 http://yoursite.com/dev/index/sayhello 就会出现 Hello one more time... 了。

发表评论

电子邮件地址不会被公开。 必填项已用*标注