Magento模块块不起作用

时间:2012-01-25 10:08:12

标签: magento

我在magento中创建了一个自定义模块。我创建了块类和phtml文件。但是localhost / dev / index.php / testimonials / index / index没有显示块?有什么想法吗?

输出应该是“加载块”。相反,我得到这个http://imageshack.us/photo/my-images/525/screenshotvs.png/

更新

<block type="testimonials/front" name="testimonialindex" template="front.phtml" />

此代码在默认句柄下工作。但它无法在<testimonials_index_index>

中工作

这是代码

<?xml version="1.0"?>
<config>
    <modules>
        <Training_Testimonials>
            <version>1.0.0</version>
        </Training_Testimonials>
    </modules>

    <frontend>
        <routers>
            <training_testimonials>
                <use>standard</use>
                <args>
                    <module>Training_Testimonials</module>
                    <frontName>testimonials</frontName>
                </args>
            </training_testimonials>
        </routers>

        <layout>
            <testimonials_layout> 

                <file>testimonials.xml</file>
            </testimonials_layout>
        </layout>

    </frontend>

    <global>
        <blocks>
            <testimonials>
                <class>Training_Testimonials_Block</class>
            </testimonials>
        </blocks>
        <helpers>
            <testimonials>
                <class>Training_Testimonials_Helper</class>
            </testimonials>
        </helpers>
      <models>
        <testimonials>  <!-- group name must be uniqu -->
            <class>Training_Testimonials_Model</class>
            <resourceModel>testimonials_mysql4</resourceModel>
        </testimonials>
        <testimonials_mysql4>
            <class>Training_Testimonials_Model_Mysql4</class>
            <entities>
                <manager>  <!--Model name -->
                    <table>testimonials</table>
                </manager>
            </entities>
        </testimonials_mysql4>
      </models>
      <resources>
        <testimonials_read>          <!-- group name_ -->
            <connection>
                <use>core_read></use>
        </connection>
        </testimonials_read> 
        <testimonials_write>          <!-- group name_ -->
            <connection>
                <use>core_write></use>
            </connection>
        </testimonials_write> 
      </resources>
    </global>

</config>

Block Class

 // app/code/local/Training/Testimonials/Block/Front.php
    class Training_Testimonials_Block_Front extends Mage_Core_Block_Template
    {
        public function layout()
        {
            echo "Block loaded";
        }
    }

布局文件

<!-- app/design/frontend/default/wireframe/layout/testimonials.xml -->
    <?xml version="1.0"?>
    <layout version="0.1.0">
        <testimonials_index_index>
            <reference name="content">
                <block type="testimonials/front" name="testimonialindex" template="front.phtml" />
            </reference>
        </testimonials_index_index>
    </layout>

3 个答案:

答案 0 :(得分:2)

正确的代码是

<layout>
       <updates>
            <testimonials> 
                <file>testimonials.xml</file>
            </testimonials>
       </updates>
</layout> 

答案 1 :(得分:0)

您需要使用IndexAction定义控制器IndexController并执行loadLayout和renderLayout。

答案 2 :(得分:0)

您的版本控制也不正确。确保每个xml文件中的模块版本相同。

<modules>
    <Training_Testimonials>
        <version>1.0.0</version>
    </Training_Testimonials>
</modules>

<layout version="0.1.0">  THIS SHOULD BE 1.0.0 OR THE VERSION ABOVE SHOULD BE 0.1.0
    <testimonials_index_index>
        <reference name="content">
            <block type="testimonials/front" name="testimonialindex" template="front.phtml" />
        </reference>
    </testimonials_index_index>
</layout>