簡體   English   中英

如何在magento admin中加載phtml文件

[英]How to load phtml file in magento admin

應用程序\\代碼\\本地\\ STW \\樹\\塊\\ Adminhtml \\ Adminblock.php

<?php


class Stw_Tree_Block_Adminhtml_Adminblock extends Mage_Adminhtml_Block_Template
{
    public function __construct()
    {
        parent::__construct();

    }

    protected function _prepareLayout()
    {
        return parent::_prepareLayout();
    }

    public function getHandleUpdates()
    {
        Zend_Debug::dump($this->getLayout()->getUpdate()->getHandles());
    }

}

應用程序\\代碼\\本地\\ STW \\樹\\控制器\\ Adminhtml \\ CustomController.php

class Stw_Tree_Adminhtml_CustomController extends Mage_Adminhtml_Controller_Action
{
    public function indexAction()
    {
        $this->loadLayout();
        $this->_setActiveMenu('mycustomtab');
        $this->renderLayout();

    }

}

應用程序\\設計\\ adminhtml \\ DEFAULT \\ DEFAULT \\布局\\ tree.xml

<?xml version="1.0"?>
<layout>
    <default>
        <reference name="content">
            <block type="tree/adminhtml_adminblock" name="tree" template="tree/myform.phtml" />
        </reference>
    </default>
</layout>

應用程序\\代碼\\本地\\ STW \\樹\\等\\ config.xml中

<?xml version="1.0"?>
<config>
    <modules>
        <Stw_Tree>
            <version>1.0.0</version>
        </Stw_Tree>
    </modules>
    <global>
        <helpers>
            <stw_tree>
                <!-- Helper definition needed by Magento -->
                <class>Mage_Core_Helper</class>
            </stw_tree>
        </helpers>
        <blocks>
            <stw_tree>
                <class>Stw_Tree_Block</class>
            </stw_tree>
        </blocks>
    </global>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <stw_tree before="Mage_Adminhtml">Stw_Tree_Adminhtml</stw_tree>
                    </modules>
                </args>
                <layout>
                    <updates>
                        <tree>
                            <file>tree.xml</file>
                        </tree>
                    </updates>
                </layout>
            </adminhtml>
        </routers>
    </admin>
</config>

我想在magento的admin部分中加載myform.phtml,但未加載任何內容。 我不明白這有什么問題。 請有人告訴我變化。 myform.phtml包含純HTML代碼

正如在config.xml中定義的塊,如下所示:-

<blocks>
    <stw_tree>
        <class>Stw_Tree_Block</class>
    </stw_tree>
 </blocks>

您需要使用相同的別名從Layout中調用此塊,如下所示:-

<layout>
    <default>
        <reference name="content">
            <block type="stw_tree/adminhtml_adminblock" name="tree" template="tree/myform.phtml" />
        </reference>
    </default>
</layout>

我不認為布局節點應該像config.xml文件中那樣位於路由器注釋中。 您應該添加一個新的adminhtml節點作為admin的同級節點,即config的直接子級。

    </admin>
    <adminhtml>
      <layout>
            <updates>
                <tree>
                    <file>tree.xml</file>
                </tree>
            </updates>
        </layout>
    </adminhtml>
</config>

暫無
暫無

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

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