自定义模块在Magento 1.9中不工作


Custom module is not working in Magento 1.9

我已经在Magento中创建了自定义模块,但它不起作用。

我的模块激活文件是app'etc'modules'Knowledge_Gain.xml .

下面是我的模块激活码:
<?xml version="1.0"?>
<config>
    <modules>
        <Knowledge_Gain>   
            <active>true</active>  
            <codePool>local</codePool> 
        </Knowledge_Gain>
    </modules>
</config>`

我的配置文件是app'code'local'Knowledge'Gain'etc'config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Knowledge_Gain>
            <version>0.1.0</version> 
        </Knowledge_Gain>
    </modules>
    <frontend>
        <routers>
            <gain>
                <use>standard</use>
                <args>
                    <module>Knowledge_Gain</module>
                    <frontName>gain</frontName>
                </args>
            </gain>
        </routers>
        <layout>  
            <updates>
                <gain>
                    <file>gain.xml</file>
                </gain>
            </updates>
        </layout>
    </frontend>
    <global>
        <blocks>
            <gain>
                <class>Knowledge_Gain_Block</class>
            </gain>
        </blocks>
    </global>
</config>`

我的控制器文件是app'code'local'Knowledge'Gain'controllers'IndexController.php

<?php
class Knowledge_Gain_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        echo "Knowledge Gain Activated";
        $this->loadLayout();  
        $this->renderLayout();
    }
}

我的块文件是app'code'local'Knowledge'Gain'Block'Trail.php

<?php
class Knowledge_Gain_Block_Trail extends Mage_Core_Block_Template
{
    public function getContent()
    {
        return "Block Activated";
    }

布局文件为app'design'frontend'rwd'default'layout'gain.xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <gain_index_index>
        <reference name="content">
            <block type="gain/trail" name="gain" template="hello.phtml" />
        </reference>
    </gain_index_index>
</layout>` 

模板文件为'app'design'frontend'rwd'default'template'hello.phtml

<?php
echo $this->getContent();
echo get_class($this);
?>

我在这段代码中做错了什么?不显示块内容。

谁来帮帮我,提前谢谢。

一切正常。我检查了一下你的模块,它工作正常。

请清除缓存系统>缓存管理>点击"刷新Magento缓存"按钮

after check your module

此模块代码是正确的。在Magento 1.9.1或更高版本中,您需要在admin中添加新的块。请遵循以下步骤:

步骤1:Admin>> Permission>> Block>>添加新的Block并保存Block

步骤2:系统>缓存管理>点击"刷新Magento缓存"按钮