2016-10-05 131 views
-1

我已创建自定义模块在Magento工作,但它不工作。自定义模块未在Magento 1.9

我模块激活文件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); 
?> 

什么,我在此代码做错了什么?块内容不显示。

任何人都请帮助我,在此先感谢。

+0

首先看看你的代码看起来正确。为了测试,将布局XML文件和模板文件移动到base/default目录,然后查看它是否可行。 –

回答

0

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

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

检查模块

0

该模块的代码是正确后。在Magento ver 1.9.1或更高版本中,您需要 在admin中添加新块。请按照以下几个步骤:

步骤1:管理员权限>> >> >>座添加新的模块,并保存块。

第二步:系统>缓存管理>点击“刷新Magento的缓存”按钮。