gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 01:41:13 25 4
gpt4 key购买 nike

我是 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>

位置:app/code/local/Digitab/Brandlogo/Block/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();
}
}

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

IndexController.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

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>

位置:app/code/local/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>

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

Data.php

<?php
class Digitab_Brandlogo_Helper_Data extends Mage_Core_Helper_Abstract
{
}

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

品牌标识.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

我得到如下输出

enter image description here

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





更新

我修改了我的文件如下,但它不工作。

位置: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>

位置:app/code/local/Digitab/Brandlogo/Block/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();
}
}

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

品牌标识 Controller

<?php

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

位置:app/code/local/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>

位置:app/code/local/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>

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

Data.php

<?php
class Digitab_Brandlogo_Helper_Data extends Mage_Core_Helper_Abstract
{
}

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

品牌标识.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

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

app/code/local/Digitab/Brandlogo/Block/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));
}
}

app/code/local/Digitab/Brandlogo/Block/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();
}
}

The main problem is with the way you have written the XML files.

位置: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

看起来不错。

我已经在我的本地机器上检查了这段代码。在此处找到屏幕截图:

enter image description here

让我知道这是否适合您。

注意::遵循我的回答中提到的确切命名约定和文件夹名称以及代码

快乐编码...

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com