我是Magento的新手。我正在尝试为Magento管理面板开发自定义模块。我的代码如下

位置:app/etc/modules

Digitab_Brandlogo.xml

<?xml version="1.0" encoding="utf-8"?>
<config>
    <modules>
        <Digitab_Brandlogo>
            <active>true</active>
            <codePool>local</codePool>
        </Digitab_Brandlogo>
    </modules>
</config>

位置:应用程序/代码/本地/Digitab/Brandlogo/块/Adminhtml

logo.php
<?php
    class Digitab_Brandlogo_Block_Adminhtml_slider extends Mage_Adminhtml_Block_Widget_Grid_Container
    {
        public function __construct()
        {
                $this->_controller = 'adminhtml_brandlogo';
                $this->_blockGroup = 'brandlogo';
                $this->_headerText = Mage::helper('brandlogo')->__('Brand Logo Manager');
            $this->_addButtonLabel = Mage::helper('brandlogo')->__('Add Brand');
                parent::__construct();
        }
    }

位置:应用程序/代码/本地/Digitab/Brandlogo/controllers/Adminhtml

IndexController.php
<?php

class Digitab_Brandlogo_Adminhtml_BrandlogoController extends Mage_Adminhtml_Controller_Action
{
    public function indexAction()
    {
           $this->loadLayout();
           $this->renderLayout();
    }
}

位置:应用程序/代码/本地/Digitab/Brandlogo/etc

config.xml
<?xml version="1.0"?>
<config>
    <modules>
        <digitab_brandlogo>
            <version>1.0.0</version>
        </digitab_brandlogo>
    </modules>
    <global>
        <models />
        <blocks />
        <resources />
        <extraconfig />
        <helpers>
            <digitab_brandlogo>
                <class>Digitab_Brandlogo_Helper</class>
            </digitab_brandlogo>
        </helpers>
    </global>
    <admin>
        <routers>
            <digitab_brandlogo>
                <use>admin</use>
                <args>
                    <module>Digitab_brandlogo</module>
                    <frontName>brandlogo</frontName>
                </args>
            </digitab_brandlogo>
        </routers>
    </admin>
    <adminhtml>
        <layout>
        <updates>
            <brandlogo>
                <file>brandlogo.xml</file>
            </brandlogo>
        </updates>
    </layout>
    </adminhtml>
</config>

位置:应用程序/代码/本地/Digitab/Brandlogo/etc

adminhtml.xml
<?xml version="1.0"?>
<config>
    <menu>
        <digitab translate="title" module="digitab_brandlogo">
            <title>Digitab</title>
            <sort_order>110</sort_order>
            <children>
                <brandlogo>
                    <title>Brand Logo</title>
                    <sort_order>1</sort_order>
                    <action>brandlogo/adminhtml_brandlogo</action>
                </brandlogo>
            </children>
        </digitab>
    </menu>
</config>

位置:应用程序/代码/本地/Digitab/Brandlogo/Helper

Data.php
<?php
class Digitab_Brandlogo_Helper_Data extends Mage_Core_Helper_Abstract
{
}

位置:app/design/adminhtml/default/default/layout

brandlogo.xml
<?xml version="1.0"?>
<layout version="0.1.0">
    <brandlogo_adminhtml_brandlogo_index>
        <reference name="content">
            <block type="brandlogo/adminhtml_brandlogo" name="brandlogo" template="test.phtml"/>
        </reference>
    </brandlogo_adminhtml_brandlogo_index>
</layout>

位置:app/design/adminhtml/default/default/template

test.phtml
ABCD

我得到如下输出

php - Magento管理模块中的显示模板-LMLPHP

如何显示模板?有人可以在这方面帮助我吗?谢谢

更新

我如下修改了我的文件,但是它不起作用。

位置:app/etc/modules

Digitab_Brandlogo.xml
<?xml version="1.0" encoding="utf-8"?>
<config>
    <modules>
        <Digitab_Brandlogo>
            <active>true</active>
            <codePool>local</codePool>
        </Digitab_Brandlogo>
    </modules>
</config>

位置:应用程序/代码/本地/Digitab/Brandlogo/块/Adminhtml

Brandlogo.php
<?php
    class Digitab_Brandlogo_Block_Adminhtml_Brandlogo extends Mage_Adminhtml_Block_Widget_Grid_Container
    {
        public function __construct()
        {
                $this->_controller = 'adminhtml_brandlogo';
                $this->_blockGroup = 'brandlogo';
                $this->_headerText = Mage::helper('brandlogo')->__('Brand Logo Manager');
            $this->_addButtonLabel = Mage::helper('brandlogo')->__('Add Brand');
                parent::__construct();
        }
    }

位置:应用程序/代码/本地/Digitab/Brandlogo/controllers/Adminhtml

BrandlogoController
<?php

class Digitab_Brandlogo_Adminhtml_BrandlogoController extends Mage_Adminhtml_Controller_Action
{
    public function indexAction()
    {
           $this->loadLayout();
           $this->renderLayout();
    }
}

位置:应用程序/代码/本地/Digitab/Brandlogo/etc

config.xml
<?xml version="1.0"?>
<config>
    <modules>
        <digitab_brandlogo>
            <version>1.0.0</version>
        </digitab_brandlogo>
    </modules>
    <global>
        <models />
        <blocks>
            <brandlogo>
                <class>Digitab_Brandlogo_Block</class>
            </brandlogo>
        </blocks>
        <resources />
        <extraconfig />
        <helpers>
            <digitab_brandlogo>
                <class>Digitab_Brandlogo_Helper</class>
            </digitab_brandlogo>
        </helpers>
    </global>
    <admin>
        <routers>
            <digitab_brandlogo>
                <use>admin</use>
                <args>
                    <module>Digitab_brandlogo</module>
                    <frontName>brandlogo</frontName>
                </args>
            </digitab_brandlogo>
        </routers>
    </admin>
    <adminhtml>
    <layout>
        <updates>
            <brandlogo>
                <file>brandlogo.xml</file>
            </brandlogo>
        </updates>
    </layout>
    </adminhtml>
</config>

位置:应用程序/代码/本地/Digitab/Brandlogo/etc

adminhtml.xml
<?xml version="1.0"?>
<config>
    <menu>
        <digitab translate="title" module="digitab_brandlogo">
            <title>Digitab</title>
            <sort_order>110</sort_order>
            <children>
                <brandlogo>
                    <title>Brand Logo</title>
                    <sort_order>1</sort_order>
                    <action>brandlogo/adminhtml_brandlogo</action>
                </brandlogo>
            </children>
        </digitab>
    </menu>
</config>

位置:应用程序/代码/本地/Digitab/Brandlogo/Helper

Data.php
<?php
class Digitab_Brandlogo_Helper_Data extends Mage_Core_Helper_Abstract
{
}

位置:app/design/adminhtml/default/default/layout

brandlogo.xml
<?xml version="1.0"?>
<layout version="0.1.0">
    <brandlogo_adminhtml_brandlogo_index>
        <reference name="content">
            <block type="brandlogo/adminhtml_brandlogo" name="brandlogo" template="test.phtml"/>
        </reference>
    </brandlogo_adminhtml_brandlogo_index>
</layout>

位置:app/design/adminhtml/default/default/template

test.phtml
ABCD

但这是行不通的。现在,我可以在管理面板中看到一个空白的白页。谢谢

最佳答案

这是一个完整的答案:

位置:app/etc/modules

Digitab_Brandlogo.xml

看起来不错。

位置:app/code/local/Digitab/Brandlogo/Block/Adminhtml

此文件夹需要包含以下文件和文件夹:

应用程序/代码/本地/Digitab/Brandlogo/块/Adminhtml/Brandlogo/Grid.php

<?php
class Digitab_Brandlogo_Block_Adminhtml_Brandlogo_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
    public function __construct()
    {
        parent::__construct();
        $this->setId('digitab_brandlogo_grid');
        $this->setDefaultSort('increment_id');
        $this->setDefaultDir('DESC');
        $this->setSaveParametersInSession(true);
        $this->setUseAjax(true);
    }

    public function getGridUrl()
    {
        return $this->getUrl('*/*/grid', array('_current'=>true));
    }
}

应用程序/代码/本地/Digitab/Brandlogo/块/Adminhtml/Brandlogo.php
<?php
class Digitab_Brandlogo_Block_Adminhtml_Brandlogo extends Mage_Adminhtml_Block_Widget_Grid_Container
{
    public function __construct()
    {
        $this->_blockGroup = 'digitab_brandlogo';
        $this->_controller = 'adminhtml_brandlogo';
        $this->_headerText = Mage::helper('digitab_brandlogo')->__('Brand Logo Manager');

        parent::__construct();
        $this->_addButtonLabel = Mage::helper('digitab_brandlogo')->__('Add Brand');
    }
}

位置:app/code/local/Digitab/Brandlogo/Helper/Data.php
<?php
class Digitab_Brandlogo_Helper_Data extends Mage_Core_Helper_Abstract {}

位置:app/code/local/Digitab/Brandlogo/controllers/Adminhtml/BrandlogoController.php
<?php
class Digitab_Brandlogo_Adminhtml_BrandlogoController extends Mage_Adminhtml_Controller_Action
{
    public function indexAction()
    {
        $this->loadLayout();
        $this->renderLayout();
    }
}



位置:app/code/local/Digitab/Brandlogo/etc

1. app/code/local/Digitab/Brandlogo/etc/config.xml下面是config.xml的代码必须如何。
<?xml version="1.0"?>
<config>
    <modules>
        <Digitab_Brandlogo>
            <version>1.0.0</version>
        </Digitab_Brandlogo>
    </modules>
    <global>
        <models />
        <blocks>
            <digitab_brandlogo>
                <class>Digitab_Brandlogo_Block</class>
            </digitab_brandlogo>
        </blocks>
        <resources />
        <extraconfig />
        <helpers>
            <digitab_brandlogo>
                <class>Digitab_Brandlogo_Helper</class>
            </digitab_brandlogo>
        </helpers>
    </global>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <digitab_brandlogo before="Mage_Adminhtml">Digitab_Brandlogo_Adminhtml</digitab_brandlogo>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
    <adminhtml>
        <layout>
            <updates>
               <brandlogo>
                    <file>brandlogo.xml</file>
               </brandlogo>
            </updates>
        </layout>
    </adminhtml>
</config>

2. app/code/local/Digitab/Brandlogo/etc/adminhtml.xml下面是config.xml的代码必须如何。
<?xml version="1.0"?>
<config>
    <menu>
        <digitab translate="title" module="digitab_brandlogo">
            <title>Digitab</title>
            <sort_order>110</sort_order>
            <children>
                <brandlogo>
                    <title>Brand Logo</title>
                    <sort_order>1</sort_order>
                    <action>adminhtml/brandlogo/index</action>
                </brandlogo>
            </children>
        </digitab>
    </menu>
</config>

位置:app/design/frontend/adminhtml/default/default/layout/brandlogo.xml
<?xml version="1.0"?>
<layout version="0.1.0">
    <adminhtml_brandlogo_index>
        <reference name="content">
            <block type="digitab_brandlogo/adminhtml_brandlogo" name="brandlogo" template="test.phtml"/>
        </reference>
    </adminhtml_brandlogo_index>
</layout>

位置:app/design/frontend/adminhtml/default/default/template/test.phtml

看起来不错

我已经在本地计算机上检查了此代码。在此处找到屏幕截图:

php - Magento管理模块中的显示模板-LMLPHP

让我知道这是否适合您。

注意::在我的答案中,按照准确的命名惯例和文件夹名称以及所提及的代码进行操作

快乐编码...

关于php - Magento管理模块中的显示模板,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35110613/

10-08 20:46