簡體   English   中英

如何在magento中加載自定義模塊的phtml

[英]How load phtml of custom module in magento

我需要知道如何在自定義模塊上加載phtml ...

我需要在我的塊上加載phtml文件...在magento中

我的代碼在下面.....我正在為我的學習創建模塊

目的...

在自定義塊中加載phtml的最佳方法是什么?

如果我有模型,像其他MVC一樣的控制器...

那么在magento中需要阻止什么。

my controller
-----------
class Packt_New_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
echo "this is my new controller ";
}
    public function newAction(){

        $this->loadLayout();
        $this->renderLayout();

    }


}

my config.xml
----------------
<?xml version="1.0" encoding="UTF-8" ?>
<config>
    <!-- module configuration -->
    <modules>
        <Packt_New>
            <version>0.0.1</version>
        </Packt_New>
    </modules>
    <!-- module configuration end -->
    <global>
        <blocks>
            <new>
                <class>Packt_New_Block</class>
            </new>
         </blocks>
         <helpers>
            <new>
                <class>Packt_New_Helper</class>
            </new> 
        </helpers>
        <models>
            <new>
                <class>Packt_New_Model </class>
            </new>
        </models>
    </global>
    <frontend>
        <routers>
            <new>
                <use>standard</use>
                <args>
                    <module>Packt_New</module>
                    <frontName>new</frontName>  
                </args>
            </new>
        </routers>
        <layout>
        <updates>
            <new>
                <file>new.xml</file>
            </new>
        </updates>
        </layout>
    </frontend>

</config>


my layout.xml
---------------------
<?xml version="1.0" encoding="UTF-8"?>
<layout>
   <!-- <default>
        <remove name="header"/>
    </default>-->
    <new_index_new>
        <refrence name="root">
            <action method="setTemplate">
                <template>page/2columns-right.phtml</template>
            </action>
        </refrence>
        <refrence name="content">
            <block type="new/newproducts" name="block_newproducts" template="new/new.phtml"></block>
        </refrence>
    </new_index_new>
</layout>

this is my block
-------------------
class Packt_New_Block_Newproducts extends Mage_Core_Block_Template
{



}

config.xml喜歡

   <layout>
        <updates>
            <unique_identifier module="YourNameSpace_Test">
                <file>yournamespace_test.xml</file>
            </unique_identifier>
        </updates>
    </layout>

app / design / frontend / default / default / layout / yournamespace_test.xml

<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
    <catalog_category_view>
        <reference name="content"> <!-- block name inside which you need to display hello world -->
            <action method="setTemplate">
                <template>yournamespace_test/catalog/yournamespace_test.phtml</template>
            </action>
        </reference>
    </catalog_category_view>
</layout>

更多信息

在magento中,布局並不復雜。 它遵循的mvc結構略有不同

在其他框架中,我們有一個供控制器使用的視圖進行渲染。

在magento中,我們有不同的結構。 說一個頁面,它分為許多塊。 該塊在布局的默認處理程序或布局的自定義處理程序中定義。

您使用的new_index_new是自定義處理程序的一個示例。 因此定義了引用,例如標題,內容。 我們使用添加此處理程序來保存一些參考。 這將具有塊詳細信息。

因此,頁面通常具有渲染mgento模板文件的phtml文件所需的各種塊。

我希望你能得到答案。 否則,請瀏覽magento中的一些博客

暫無
暫無

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

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