我正在使用Magento 1.8.1.0版本。
我正在尝试创建一个新的自定义块模块,该模块将用于创建新的主页。
- 命名空间:十字军
- 模块:CLHomePage
- 街区类型:十字军东征
- 类:Qwerty(仅在测试时才适用)
- 设计包:十字军
- 主题:默认
这是我到目前为止所拥有的:
\ app \ etc \ modules \ Crusader_All.xml
<?xml version="1.0"?>
<config>
<modules>
<Crusader_CLHomePage>
<active>true</active>
<codePool>local</codePool>
</Crusader_CLHomePage>
</modules>
</config>
\ app \ code \ local \ Crusader \ CLHomePage \ etc \ config.xml
<?xml version="1.0"?>
<config>
<modules>
<Crusader_CLHomePage>
<version>0.0.1</version>
</Crusader_CLHomePage>
</modules>
<global>
<blocks>
<crusaderhome>
<class>Crusader_CLHomePage_Block</class>
</crusaderhome>
</blocks>
</global>
</config>
\ app \ code \ local \ Crusader \ CLHomePage \ Block \ Qwerty.php
<?php
class Crusader_CLHomePage_Block_Qwerty extends Mage_Core_Block_Template
{
// Methods (optional)
}
?>
\ app \ design \ frontend \ crusader \ default \ layout \ local.xml
<?xml version="1.0" ?>
<layout>
<cms_index_index>
<reference name="content">
<block type="core/template" name="homepage" template="crusader/home.phtml">
<block type="crusaderhome/qwerty" name="homeads" as="homeads" template="crusader/homeads.phtml" />
</block>
</reference>
</cms_index_index>
</layout>
\ app \ design \ frontend \ crusader \ default \ template \ crusader \ home.phtml
<div id="home">
<p>Home Wrapper</p>
<?php echo $this->getChildHtml('homeads'); ?>
</div>
\ app \ design \ frontend \ crusader \ default \ template \ crusader \ homeads.phtml
<p>Adverts</p>
现在,有了上述内容,我的主页上仅显示“ Home Wrapper”,因此home.phtml
显示了的内容,但不显示的内容homeads.phtml
。
如果我改变了块类型homeads
来core/template
,它的工作原理,我看到两个“家包装”和“广告”。因此,我知道问题出在我的新方块类型(称为十字军东征)上。
我在这里做错什么了?
编辑
经过回答的建议后,我已经如下更新了一些文件,但仍然无法正常工作:
\ app \ etc \ modules \ Crusader_Home.xml
<?xml version="1.0"?>
<config>
<modules>
<Crusader_Home>
<active>true</active>
<codePool>local</codePool>
</Crusader_Home>
</modules>
</config>
\ app \ code \ local \ Crusader \ Home \ etc \ config.xml
<?xml version="1.0"?>
<config>
<modules>
<Crusader_Home>
<version>1.0.0</version>
</Crusader_Home>
</modules>
<global>
<blocks>
<crusader_home>
<class>Crusader_Home_Block</class>
</crusader_home>
</blocks>
</global>
</config>
\ app \ code \ local \ Crusader \ Home \ Block \ Qwerty.php
<?php
class Crusader_Home_Block_Qwerty extends Mage_Core_Block_Template
{
// Methods (optional)
}
?>
\ app \ design \ frontend \ crusader \ default \ layout \ local.xml(简化为仅使用一个块,而不是我之前尝试过的嵌套块)
<?xml version="1.0" ?>
<layout>
<cms_index_index>
<reference name="content">
<block type="crusader_home/qwerty" name="homepage" template="crusader/home.phtml" />
</reference>
</cms_index_index>
</layout>
\ app \ design \ frontend \ crusader \ default \ template \ crusader \ home.phtml
<p>Home</p>
所以我仍然没有任何表现。
在@FabianBlechschmidt提示后,我打开了日志,并在exception.log中显示:
2014-04-09T14:04:54+00:00 ERR (3):
exception 'Mage_Core_Exception' with message 'Invalid block type: Crusader_Home_Block_Qwerty' in W:\stores\magento-dev\app\Mage.php:595
Stack trace:
#0 W:\stores\magento-dev\includes\src\__default.php(27744): Mage::throwException('Invalid block t...')
#1 W:\stores\magento-dev\includes\src\__default.php(27686): Mage_Core_Model_Layout->_getBlockInstance('crusader_home/q...', Array)
#2 W:\stores\magento-dev\includes\src\__default.php(27721): Mage_Core_Model_Layout->createBlock('crusader_home/q...', 'homepage')
#3 W:\stores\magento-dev\includes\src\__default.php(27488): Mage_Core_Model_Layout->addBlock('crusader_home/q...', 'homepage')
#4 W:\stores\magento-dev\includes\src\__default.php(27454): Mage_Core_Model_Layout->_generateBlock(Object(Mage_Core_Model_Layout_Element), Object(Mage_Core_Model_Layout_Element))
#5 W:\stores\magento-dev\includes\src\__default.php(27459): Mage_Core_Model_Layout->generateBlocks(Object(Mage_Core_Model_Layout_Element))
#6 W:\stores\magento-dev\includes\src\__default.php(13895): Mage_Core_Model_Layout->generateBlocks()
#7 W:\stores\magento-dev\includes\src\__default.php(11274): Mage_Core_Controller_Varien_Action->generateLayoutBlocks()
#8 W:\stores\magento-dev\includes\src\__default.php(11213): Mage_Cms_Helper_Page->_renderPage(Object(Mage_Cms_IndexController), 'home')
#9 W:\stores\magento-dev\app\code\core\Mage\Cms\controllers\IndexController.php(45): Mage_Cms_Helper_Page->renderPage(Object(Mage_Cms_IndexController), 'home')
#10 W:\stores\magento-dev\includes\src\__default.php(13969): Mage_Cms_IndexController->indexAction()
#11 W:\stores\magento-dev\includes\src\__default.php(18331): Mage_Core_Controller_Varien_Action->dispatch('index')
#12 W:\stores\magento-dev\includes\src\__default.php(17865): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#13 W:\stores\magento-dev\includes\src\__default.php(20465): Mage_Core_Controller_Varien_Front->dispatch()
#14 W:\stores\magento-dev\app\Mage.php(684): Mage_Core_Model_App->run(Array)
#15 W:\stores\magento-dev\index.php(176): Mage::run('crusadergifts', 'store')
#16 {main}
有什么想法吗?。??
编辑2
@Malachy找到了答案...是编译器。我禁用了编译器,它现在似乎可以工作了。
exception 'Mage_Core_Exception' with message 'Invalid block type: Crusader_Home_Block_Qwerty'