【问题标题】:Magento custom module block not workingMagento 自定义模块块不起作用
【发布时间】:2016-09-28 11:56:00
【问题描述】:

我正在使用 cms 页面中调用我的自定义模块块

{{block type="customreviews/reviews" name="customreviews_reviews" template="Customreviews/reviews.phtml"}}

我的模块配置文件如下:

<config>
<modules>
    <Suave_Customreviews>
        <version>0.0.1</version>
    </Suave_Customreviews>
</modules>

<global>
    <models>
        <customreviews>
            <class>Suave_Customreviews_Model</class>
        </customreviews>
    </models>
    <blocks>
        <customreviews>
            <class>Suave_Customreviews_Block</class>
        </customreviews>
    </blocks>
    <herlps>
        <customreviews>
            <class>Suave_Customreviews_Helper</class>
        </customreviews>
    </herlps>
</global>

<frontend>
    <routers>
        <customreview>
            <use>standard</use>
            <args>
                <module>Suave_Customreviews</module>
                <frontName>customreviews</frontName>
            </args>
        </customreview>
    </routers>
    <layout>
        <updates>
            <customreviews>
                <file>Customreview.xml</file>
            </customreviews>
        </updates>
    </layout>
</frontend>

我在名为Reviews.php 的模块中创建的块php 文件是

class Suave_Customreviews_Model_Reviews extends Mage_Core_Block_Template

{

public function firstTenCategoryReviews()
{
    $data = Mage::getSingleton('customreviews/reviews')->firstTenCategoryReviews();
    return $data;
}

}

我的 magento 版本是 1.9.2.4 我已在 magento 管理员块权限中允许 customreviews/reviews,但仍然无法正常工作。

【问题讨论】:

  • reviews.phtml 文件的内容是什么?
  • 这里是review.phtml的内容 echo "123123123"; $reviews = $this->firstTenCategoryReviews();回声'
    '; print_r($reviews);回声'
    ';

标签: magento module model block


【解决方案1】:

有块类是错误的。应该是

Suave_Customreviews_Block_Reviews extends Mage_Core_Block_Template

【讨论】:

    【解决方案2】:

    请检查您的 xml 文件是否缺少节点。

    <config>
    <modules>
        <Suave_Customreviews>
            <version>0.0.1</version>
        </Suave_Customreviews>
    </modules>
    
    <global>
        <models>
            <customreviews>
                <class>Suave_Customreviews_Model</class>
            </customreviews>
        </models>
        <blocks>
            <customreviews>
                <class>Suave_Customreviews_Block</class>
            </customreviews>
        </blocks>
        <herlps>
            <customreviews>
                <class>Suave_Customreviews_Helper</class>
            </customreviews>
        </herlps>
    </global>
    
    <frontend>
        <routers>
            <customreview>
                <use>standard</use>
                <args>
                    <module>Suave_Customreviews</module>
                    <frontName>customreviews</frontName>
                </args>
            </customreview>
        </routers>
        <layout>
            <updates>
                <customreviews>
                    <file>Customreview.xml</file>
                </customreviews>
            </updates>
        </layout>
    </frontend>
    </config>  <!-- Check if you missed this node  -->
    

    根据 config.xml 文件中提到的代码,您缺少 &lt;/config&gt; 节点。我假设您在 xml 文件中使用了 &lt;?xml version="1.0"?&gt; 作为第一行。

    你也试过 Suman Singh 提到的吗?

    【讨论】:

      【解决方案3】:

      在google了很多之后,我发现了这个问题。

      我使用的模块名称是customreviews,但模型名称和我命名的块php文件是Reviews.php。

      默认情况下,magento 会检查以模块名称命名的模块和块文件。

      所以我将模型和块 php 文件重命名为模块名称并且它起作用了。

      正如 Suman Singh 提到的,我的块代码也存在问题。

      感谢苏曼的更正。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-17
        • 2012-06-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-22
        相关资源
        最近更新 更多