0

我在自己的客户模块中创建了一个新块,这是 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')

但它会引发此异常“无效块类型”。有什么帮助吗?

4

3 回答 3

2

createBlock() 方法将接收整个块别名 ( nauba_customer/list_ordercrosssell),而不仅仅是ordercrosssell. getChildHtml() 可以接受的原因只是ordercrosssell因为子块的名称是在布局xml中定义的。

不完全确定您的 layout.xml 可能有什么问题,但您可能应该在别名中删除下划线。因此,为了便于使用,不要nauba_customer只使用naubacustomer或理想情况下稍微短一些的东西。

我不是 100% 确定这是否是一个问题,但总的来说,最好遵循@Herve 提到的现有约定,在类别名中使用下划线与斜线,b/c 事情可能会有点毛茸茸。

于 2012-08-24T04:33:07.817 回答
0

在某些情况下(Magento 1.9),如果我们忘记在块 PHP 文件中使用构造函数,然后将其放入,问题将得到修复:

 protected function _construct()
    {
        parent::_construct();
    }
于 2018-02-27T12:40:22.870 回答
0

在其他一些情况下(Magento 1.9),如果我们有错误的文件权限/所有权,我们会得到同样的异常。修复权限/所有权解决了它。希望它可以节省别人几个小时...

于 2019-10-09T19:50:49.587 回答