-
13-12-2019 - |
题
我有一个自定义模块,具有以下内容:
magento-project/app/code/local/Hunique/Customs/etc/config。xml
<?xml version="1.0" ?>
<config>
<modules>
<Hunique_Customs>
<version>1.0.1</version>
</Hunique_Customs>
</modules>
<global>
<models>
<custommodule>
<class>Hunique_Customs_Model</class>
<resourceModel>custommodule_resource</resourceModel>
</custommodule>
<custommodule_resource>
<class>Hunique_Customs_Model_Resource</class>
<entities>
<custommodule>
<table>custommodule</table>
</custommodule>
<questions>
<table>questions</table>
</questions>
<answers>
<table>answers</table>
</answers>
</entities>
</custommodule_resource>
</models>
<resources>
<custommodule_setup>
<setup>
<module>Hunique_Customs</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</custommodule_setup>
<custommodule_read>
<connection>
<use>core_read</use>
</connection>
</custommodule_read>
<custommodule_write>
<connection>
<use>core_write</use>
</connection>
</custommodule_write>
</resources>
<blocks>
<custommodule>
<class>Hunique_Customs_Block</class>
</custommodule>
</blocks>
<helpers>
<hunique_customs>
<class>Hunique_Customs_Helper</class>
</hunique_customs>
</helpers>
</global>
<frontend>
<routers>
<custommodule>
<use>standard</use>
<args>
<module>Hunique_Customs</module>
<frontName>custommodule</frontName>
</args>
</custommodule>
</routers>
<layout>
<updates>
<custommodule>
<file>custommodule.xml</file>
</custommodule>
</updates>
</layout>
</frontend>
<admin>
<routers>
<adminhtml>
<use>admin</use>
<args>
<modules>
<Hunique_Customs before="Mage_Adminhtml">Hunique_Customs</Hunique_Customs>
</modules>
</args>
</adminhtml>
</routers>
</admin>
<adminhtml>
<layout>
<updates>
<custommodule>
<file>custommodule.xml</file>
</custommodule>
</updates>
</layout>
</adminhtml>
然后我有/magento-project/app/code/local/Hunique/Customs/etc/adminhtml。同一文件夹中的xml
<config>
<menu>
<hunique>
<title>Hunique</title>
<sort_order>1</sort_order>
<children>
<customs_qa module="hunique_customs">
<title>Questions And Answers</title>
<sort_order>1</sort_order>
<action>adminhtml/custommodule</action>
</customs_qa>
</children>
</hunique>
</menu>
那么在设计中,我有:/magento-project/app/design/adminhtml/default/default/layout/custommodule。xml
<?xml version="1.0"?>
<layout>
<adminhtml_custommodule_index>
<reference name="content">
<block type="core/template" output="toHtml" name="templateBlock" template="custommodule/questions-and-answers.phtml" />
</reference>
</adminhtml_custommodule_index>
</layout>
我有文件/magento- project/app/design/adminhtml/default/default/templates/custommodule/questions-and-answers。phtml但现在只包含一个带有TEST的h1标签。
我也有控制器:/magento-project/app/code/local/Hunique/Customs/controllers/CustommoduleController。php的
<?php
class Hunique_Customs_CustommoduleController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
var_dump(Mage::getSingleton('core/layout')->getUpdate()->getHandles());
$this->loadLayout();
$this->renderLayout();
}
}
我有var转储,看看我是否有任何句柄,但这是一个空数组。我的页面从管理菜单加载。.
我的路线和管理菜单工作正常,我只是不能让我的phtml显示。..有人能给我指出正确的方向吗?
解决方案
您提供的代码应该按原样工作。虽然你的 config.xml
和 adminhtml.xml
文件没有他们的 <config>
标签关闭,我怀疑你只是在这里粘贴代码时犯了这个错误,因为否则你会看到一个错误,而不是一个空内容区域的页面。
我的建议是,您应该搜索文件名中的拼写错误或错误的目录嵌套。此外,您的 var_dump
为空,因为您尝试在实际加载布局之前显示布局句柄。你必须在你的动作中切换前两行:
public function indexAction() {
$this->loadLayout();
var_dump(Mage::getSingleton('core/layout')->getUpdate()->getHandles());
$this->renderLayout();
}
此外,您还可以确保您的管理面板使用 default/default
包/主题或它在后备链中。如果它使用其他软件包(例如 custompackage/default
),它不会看进去 default/default
.如果您不确定,您可以随时将布局更新xml和模板放入 base/default
相反。它不存在于管理面板中,但您可以创建它,它将用作最后的后备。
如果有帮助,请告诉我。