由于某些原因,我无法显示此控制器。请问我在这里做错了什么?控制器工作正常,但由于某种原因,我无法使用此方法显示块。
Here is the indexController, which is basically adding the layout and rendering it out too. The indexController is located in the module controller folder.
IndexController.php
<?php
class MasteringMagento_ChapterBlockTemplate_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
return $this->renderLayout();
}
}
Here is the Welcome block which is located in the MasteringMagento/ChapterBlockTemplate/Block/Welcome
Welcome.php
class MasteringMagento_ChapterBlockTemplate_Block_Welcome extends Mage_Core_Block_Template
{
public function __construct()
{
parent::__construct();
$this->setTemplate('chapterblocktemplate/welcome.phtml');
}
}
This is the config file which is located in the etc folder. I have just posted a full config.xml file. I cant seem to see anything wrong with the code.
config.xml
<?xml version="1.0"?>
<config>
<modules>
<MasteringMagento_ChapterBlockTemplate>
<version>0.0.0</version>
</MasteringMagento_ChapterBlockTemplate>
</modules>
<global>
<models>
<masteringmagento_chapterblocktemplate>
<class>MasteringMagento_ChapterBlockTemplate_Model</class>
<resourceModel>masteringmagento_chapterblocktemplate_resource</resourceModel>
</masteringmagento_chapterblocktemplate>
<masteringmagento_chapterblocktemplate_resource>
<class>MasteringMagento_ChapterBlockTemplate_Model_Resource</class>
</masteringmagento_chapterblocktemplate_resource>
</models>
<blocks>
<masteringmagento_chapterblocktemplate>
<class>MasteringMagento_ChapterBlockTemplate_Block</class>
</masteringmagento_chapterblocktemplate>
</blocks>
<helpers>
<masteringmagento_chapterblocktemplate>
<class>MasteringMagento_ChapterBlockTemplate_Helper</class>
</masteringmagento_chapterblocktemplate>
</helpers>
</global>
Here is the frontend route which is part of the config file
<frontend>
<routers>
<chapterblocktemplate>
<use>standard</use>
<args>
<frontName>chapterblocktemplate</frontName>
<module>MasteringMagento_ChapterBlockTemplate</module>
</args>
</chapterblocktemplate>
</routers>
<layout>
<updates>
<chapterblocktemplate>
<file>chapterblocktemplate.xml</file>
</chapterblocktemplate>
</updates>
</layout>
</frontend>
</config>
Here is the layout file, which is located in magento default layout folder
chapterblocktemplate.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<chapterblocktemplate_index_index>
<update handle="page_two_columns_right"/>
<reference name="content">
<!--Second way to load a template-->
<block type="chapterblocktemplate/welcome"/>
</reference>
</chapterblocktemplate_index_index>
</layout>
i also created a template folder name chapterblocktemplate and i have a file named welcome.phtml in it.
我已经更新了整个代码,仍然没有运气。我错过了什么?这有点奇怪。 感谢
答案 0 :(得分:0)
我认为您错过了在app / etc / MasteringMagento_ChapterBlockTemplate.xml下创建模块配置文件
请确保这一点。
答案 1 :(得分:0)
在布局中添加
<frontend>
<routers>
<chapterblocktemplate>
<use>standard</use>
<args>
<module>MasteringMagento_ChapterBlockTemplate</module>
<frontName>chapterblocktemplate</frontName>
</args>
</chapterblocktemplate>
</routers>
<layout>
<updates>
<chapterblocktemplate>
<file>chapterblocktemplate.xml</file>
</chapterblocktemplate>
</updates>
</layout>
</frontend>
答案 2 :(得分:0)
在<frontend>
config.xml
标记中添加前端路由器配置
<routers>
<chapterblocktemplate>
<use>standard</use>
<args>
<module>MasteringMagento_ChapterBlockTemplate</module>
<frontName>chapterblocktemplate</frontName>
</args>
</chapterblocktemplate>
</routers>
答案 3 :(得分:0)
解决了问题。只是想感谢你们每个人的贡献。
问题发生在etc / config.xml
上我用下面的代码替换了全局部分,而不是同时拥有namespace_modulename(masteringmagento_chapterblocktemplate),你应该只有模块名称(chapterblocktemplate)。
<global>
<models>
<chapterblocktemplate>
<class>MasteringMagento_ChapterBlockTemplate_Model</class>
<resourceModel>masteringmagento_chapterblocktemplate_resource</resourceModel>
</chapterblocktemplate>
<chapterblocktemplate_resource>
<class>MasteringMagento_ChapterBlockTemplate_Model_Resource</class>
</chapterblocktemplate_resource>
</models>
<blocks>
<chapterblocktemplate>
<class>MasteringMagento_ChapterBlockTemplate_Block</class>
</chapterblocktemplate>
</blocks>
<helpers>
<chapterblocktemplate>
<class>MasteringMagento_ChapterBlockTemplate_Helper</class>
</chapterblocktemplate>
</helpers>
</global>
希望它可以帮助别人:) 享受