簡體   English   中英

Magento自定義模塊塊不起作用

[英]Magento custom module block not working

我正在使用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,但仍然無法正常工作。

有塊類是錯誤的。 它應該是

Suave_Customreviews_Block_Reviews extends Mage_Core_Block_Template

請檢查您的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文件中提到的代碼,您缺少</config>節點。 我假設您已將<?xml version="1.0"?>用作xml文件的第一行。

您還嘗試了Suman Singh提到的內容嗎?

經過大量的谷歌搜索后,我發現了問題。

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

默認情況下,magento將檢查名為模塊名稱的模塊和塊文件。

因此,我將模型重命名並將php文件重命名為模塊名稱,然后它起作用了。

正如Suman Singh所述,我的塊代碼也存在問題。

感謝Suman的更正。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM