我已創建自定義模塊在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);
?>
什麼,我在此代碼做錯了什麼?塊內容不顯示。
任何人都請幫助我,在此先感謝。
首先看看你的代碼看起來正確。爲了測試,將佈局XML文件和模板文件移動到base/default目錄,然後查看它是否可行。 –