【问题标题】:Custom admin backend module page in Magento 1.x - blank page (layout not loading)Magento 1.x 中的自定义管理后端模块页面 - 空白页面(布局未加载)
【发布时间】:2016-01-04 14:49:15
【问题描述】:

我正在尝试遵循 http://alanstorm.com/magento_admin_hello_world_revisited 教程并在 magento 1.9.x 中设置自定义管理模块。

可下载的样板 http://alanstorm.com/2013/projects/Pulsestorm_Adminhello.tar 工作正常。当它上传到 magento 时,我可以看到以下内容:

当您单击示例菜单项时,您会看到一个空白页面。

所以,我现在想将我自己的.phtml 加载到视图中。因此,在模块的config.xml 上,我添加了以下内容:

app/code/community/Pulsestorm/Adminhello/etc/config.xml

<?xml version="1.0"?>
<config>
    ...
    <adminhtml>
        <layout>
            <updates>
                <adminhello>
                    <file>adminhello.xml</file>
                </adminhello>
            </updates>
        </layout>
    </adminhtml>
</config>

然后我创建了以下布局 xml 文件:

app/design/adminhtml/default/default/layout/adminhello.xml

<?xml version="1.0"?>
<layout version="1.0">

    <adminhtml_adminhello_index>
        <block type="core/template" output="toHtml" name="templateBlock" template="adminhello/index.phtml">
    </adminhtml_adminhello_index>

</layout>

然后我创建了以下模板 phtml 文件:

app/design/adminhtml/default/default/template/adminhello/index.phtml

<b>Hello World</b>

当我刷新页面时(Pulse Storm -> Example),我仍然看到一个空白页面。我在这里错过了什么?

【问题讨论】:

    标签: php xml magento


    【解决方案1】:

    这可能对你有帮助

    app\code\community\Pulsestorm\Adminhello\etc\config.xml

    <?xml version="1.0"?>
    <config>
      <modules>
        <Pulsestorm_Adminhello>
          <version>0.1.0</version>
        </Pulsestorm_Adminhello>
      </modules>
      <global>
        <helpers>
          <adminhello>
            <class>Pulsestorm_Adminhello_Helper</class>
          </adminhello>
        </helpers>
        <blocks>
          <adminhello>
            <class>Pulsestorm_Adminhello_Block</class>
          </adminhello>
        </blocks>
      </global>
      <admin>
        <routers>
          <adminhello>
            <use>admin</use>
            <args>
              <module>Pulsestorm_Adminhello</module>
              <frontName>admin_adminhello</frontName>
            </args>
          </adminhello>
        </routers>
      </admin>
      <adminhtml>
        <menu>
          <adminhello module="adminhello">
            <title>Adminhello</title>
            <sort_order>100</sort_order>
            <children>
              <adminhellobackend module="adminhello">
                <title>Adminhello</title>
                <sort_order>0</sort_order>
                <action>admin_adminhello/adminhtml_adminhellobackend</action>
              </adminhellobackend>
            </children>
          </adminhello>
        </menu>
        <acl>
          <resources>
            <all>
              <title>Allow Everything</title>
            </all>
            <admin>
              <children>
                <adminhello translate="title" module="adminhello">
                  <title>Adminhello</title>
                  <sort_order>1000</sort_order>
                  <children>
              <adminhellobackend translate="title">
                <title>Adminhello</title>
              </adminhellobackend>
                  </children>
                </adminhello>
              </children>
            </admin>
          </resources>
        </acl>
        <layout>
          <updates>
            <adminhello>
              <file>adminhello.xml</file>
            </adminhello>
          </updates>
        </layout>
      </adminhtml>
    </config> 
    

    app\code\community\Pulsestorm\Adminhello\Block\Adminhtml\Adminhellobackend.php

    <?php
    class Pulsestorm_Adminhello_Adminhtml_AdminhellobackendController extends Mage_Adminhtml_Controller_Action
    {
        public function indexAction()
        {
           $this->loadLayout();
           $this->_title($this->__("Adminhello"));
           $this->renderLayout();
        }
    }
    

    app\design\adminhtml\default\default\layout\adminhello.xml

    <?xml version="1.0"?>
    <layout version="0.1.0">
      <adminhello_adminhtml_adminhellobackend_index>
        <reference name="content">
          <block type="adminhello/adminhtml_adminhellobackend" name="adminhellobackend" template="adminhello/adminhellobackend.phtml"/>
        </reference>
      </adminhello_adminhtml_adminhellobackend_index>
    </layout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      相关资源
      最近更新 更多