分享

Magento 1.8.0.0 创建你的第一个模块

 烈哥哥 2015-09-29


自己在创建第一个模块时,用了三天,心塞!!国内的文章太少了。跑去看英文!




1. 创建以下目录(有些暂时用不到,先创建起来)


app/code/local/Test/Mymodule/Block   

app/code/local/Test/Mymodule/controllers  

app/code/local/Test/Mymodule/etc  

app/code/local/Test/Mymodule/Helper  

app/code/local/Test/Mymodule/Model  

app/code/local/Test/Mymodule/sql  




2. 创建config.xml

/app/code/local/Test/Mymodule/etc/config.xml

<?xml version="1.0" encoding="utf-8"?> 
<config>     
    <modules> 
        <Test_Mymodule> 
            <version>0.1.0</version> 
        </Test_Mymodule> 
    </modules> 
     <!-- This node contains parameters, available on frontend --> 
    <frontend> 
        <!-- Module aliases are located in this block --> 
        <routers> 
            <!-- This node's name should be the same as our alias --> 
            <Mymodule> 
                <!-- use parameter specifies which of basic routers needs to be used. 
                This can be "standard" for frontend or "admin" for backend --> 
                <use>standard</use> 
                <!-- router arguments block --> 
                <args> 
                    <!-- This parameter specifies the full name of out module --> 
                    <module>Test_Mymodule</module> 
                    <!-- This parameter sets module alias --> 
                    <frontName>mymodule</frontName> 
                </args> 
            </Mymodule> 
        </routers> 
      <layout> 
            <updates>                
                <helloworld>                     
                    <file>mymodule.xml</file> 
                </helloworld> 
            </updates> 
        </layout> 
    </frontend> 
</config>  

3. 创建Test_Mymodule.xml

/app/etc/modules/Test_Mymodule.xml

<?xml version="1.0" encoding="utf-8"?> 
<config>     
    <modules> 
        <Test_Mymodule> 
           <active>true</active> 
           <codePool>local</codePool> 
        </Test_Mymodule> 
    </modules> 
</config> 

4. 创建IndexController.php控制器

/app/code/local/Test/Mymodule/controllers/IndexController.php

class Test_Mymodule_IndexController extends Mage_Core_Controller_Front_Action 
{ 

   public function indexAction() 
    { 
     echo "test"; 
    } 
}


5. 如果没有在后台开启url重写的话,打开模块的url为:


http:///index.php/mymodule/index/index



    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多