我在自己的Customer模块中创建了一个新块,这里是config.xml:
<?xml version="1.0"?>
<config>
<modules>
<Nauba_Customer>
<version>1.6.2.0.3</version>
</Nauba_Customer>
</modules>
<global>
<resources>
<nauba_customer_setup>
<setup>
<module>Nauba_Customer</module>
</setup>
</nauba_customer_setup>
</resources>
<blocks>
<nauba_customer>
<class>Nauba_Customer_Block</class>
</nauba_customer>
<customer>
<rewrite>
<form_register>Nauba_Customer_Block_Form_Register</form_register>
</rewrite>
</customer>
</blocks>
<models>
<customer>
<rewrite>
<customer>Nauba_Customer_Model_Customer</customer>
</rewrite>
</customer>
</models>
</global>
<frontend>
<routers>
<customer>
<args>
<modules>
<Nauba_Customer before="Mage_Customer">Nauba_Customer</Nauba_Customer>
</modules>
</args>
</customer>
</routers>
</frontend>
</config>
现在我试图在主页中调用它,所以我在page.xml布局中指定了它:
<!-- this is only the home page section -->
<page_homepage translate="label">
<label>Homepage</label>
<reference name="root">
<!--reference name="head">
<action method="removeItem"><type>skin_css</type><name>css/styles.css</name></action>
<action method="removeItem"><type>skin_css</type><name>css/styles-ie.css</name></action>
<action method="removeItem"><type>skin_css</type><name>css/widgets.css</name></action>
<action method="removeItem"><type>skin_css</type><name>css/print.css</name></action>
</reference-->
<block type="page/html" name="category_links" template="page/html/category_links.phtml" />
<block type="cms/block" name="homepage_slider_image_1" as="homepage_slider_image_1">
<action method="setBlockId"><block_id>homepage_slider_image_1</block_id></action>
</block>
<block type="cms/block" name="homepage_slider_image_2" as="homepage_slider_image_2">
<action method="setBlockId"><block_id>homepage_slider_image_2</block_id></action>
</block>
<block type="cms/block" name="homepage_slider_image_3" as="homepage_slider_image_3">
<action method="setBlockId"><block_id>homepage_slider_image_3</block_id></action>
</block>
<block type="cms/block" name="homepage_slider_image_4" as="homepage_slider_image_4">
<action method="setBlockId"><block_id>homepage_slider_image_4</block_id></action>
</block>
<block type="cms/block" name="homepage_event_banner_1" as="homepage_event_banner_1">
<action method="setBlockId"><block_id>homepage_event_banner_1</block_id></action>
</block>
<block type="cms/block" name="homepage_event_banner_2" as="homepage_event_banner_2">
<action method="setBlockId"><block_id>homepage_event_banner_2</block_id></action>
</block>
<block type="cms/block" name="homepage_event_banner_3" as="homepage_event_banner_3">
<action method="setBlockId"><block_id>homepage_event_banner_3</block_id></action>
</block>
<block type="nauba_customer/list_ordercrosssell" name="ordercrosssell" as="ordercrosssell" template="nauba_customer/list/ordercrosssell.phtml">
</block>
<action method="setTemplate"><template>page/home.phtml</template></action>
<!-- Mark root page block that template is applied -->
<action method="setIsHandle"><applied>1</applied></action>
<action method="setLayoutCode"><name>page_homepage</name></action>
</reference>
</page_homepage>
但是当我在主页模板中调用它时它不起作用:
($this->getChildHtml('ordercrosssell'))
我也尝试通过以下方式创建它:
$this->getLayout()->createBlock('ordercrosssell')
但它会引发此异常“无效的阻止类型”。有什么帮助吗?
答案 0 :(得分:2)
createBlock()方法将接受整个块别名(nauba_customer/list_ordercrosssell
),而不仅仅是ordercrosssell
。 getChildHtml()只能接受ordercrosssell
的原因是因为子块的名称是在布局xml中定义的。
不完全确定layout.xml可能有什么问题,但你应该在你的别名中删除下划线。因此,nauba_customer
代替naubacustomer
而不是{{1}},或者理想情况下的某些内容略短于易于使用的内容。
我不是百分之百确定这是否是一个问题,但总的来说,最好遵循现有的惯例,因为@Herve提到了下划线与类别名中的斜杠,b / c事情可能会有些毛茸茸。
答案 1 :(得分:0)
在某些情况下(Magento 1.9),如果我们忘记在块PHP文件中使用构造函数,那么把它放在一起,问题就会解决:
protected function _construct()
{
parent::_construct();
}
答案 2 :(得分:0)
在其他情况下(Magento 1.9),如果我们具有错误的文件权限/所有权,我们将获得相同的异常。解决权限/所有权问题解决了。希望它可以节省别人几个小时的时间...