【问题标题】:Magento Admin Layout and TemplateMagento 管理员布局和模板
【发布时间】:2015-11-27 17:05:10
【问题描述】:

我是 Magento 的新手。我正在学习 Magento 模块开发。我正在尝试遵循这个 (http://www.opensourceforwebtechnologies.com/create-custom-admin-module-in-magento/) 教程。在这方面,我的代码如下。

Easylife_All.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Helloworld>
            <active>true</active>
            <codePool>local</codePool>
        </Easylife_Helloworld>
    </modules>
</config>

这个文件的位置是

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Helloworld>
            <version>0.1.0</version>
        </Easylife_Helloworld>
    </modules>
    <frontend>
        <routers>
            <helloworld>
                <use>standard</use>
                <args>
                    <module>Easylife_Helloworld</module>
                    <frontName>helloworld</frontName>
                </args>
            </helloworld>
        </routers>
        <layout>
            <updates>
                <helloworld>
                    <file>helloworld.xml</file>
                </helloworld>
            </updates>
        </layout>
    </frontend>


    <admin>
        <routers>
            <helloworld>
                <use>admin</use>
                <args>
                    <module>Easylife_Helloworld</module>
                    <frontName>admin_helloworld</frontName>
                </args>
            </helloworld>
        </routers>
    </admin>
    <adminhtml>
        <layout>
            <updates>
                <helloworld>
                    <file>easylife/helloworld.xml</file>
                </helloworld>
            </updates>
        </layout>
        <menu>
            <helloworld translate="title" module="adminhtml">
                <title>My Module</title>
                <sort_order>100</sort_order>
                <children>
                    <set_time>
                        <title>Address Book</title>
                        <action>admin_helloworld/adminhtml_index</action>
                    </set_time>
                </children>
            </helloworld>
        </menu>
    </adminhtml>


    <global>
        <blocks>
            <helloworld>
                <class>Easylife_Helloworld_Block</class>
            </helloworld>
        </blocks>
        <models>
            <helloworld>
                <class>Easylife_Helloworld_Model</class>
                <resourceModel>helloworld_resource</resourceModel>
            </helloworld>
            <helloworld_resource>
                <class>Easylife_Helloworld_Model_Resource</class>
                <entities>
                    <helloworld>
                        <table>helloworld</table>
                    </helloworld>
                </entities>
            </helloworld_resource>
        </models>
        <resources>
            <helloworld_setup>
                <setup>
                    <module>Easylife_Helloworld</module>  
                    <class>Easylife_Helloworld_Model_Resource_Setup</class> 
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </helloworld_setup>
            <helloworld_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </helloworld_read>
            <helloworld_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </helloworld_write>
        </resources>
    </global>
</config>

这个文件的位置

IndexController.php

class Easylife_Helloworld_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
{

    public function indexAction()
    {
        $this->loadLayout();
        $this->renderLayout();
    }

}

这个文件的位置是

helloworld.xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <helloworld_adminhtml_index_index>
        <reference name="content">
            <block name="helloworld_grid" type="helloworld/adminhtml_grid" template="helloworld/helloworld.phtml"></block>
        </reference>
    </helloworld_adminhtml_index_index>
</layout>

此文件的位置

helloworld.phtml

<h1>Success!!!!!!!!!!!!!</h1>

这个文件的位置

我正在尝试浏览以下网址

http://localhost/magento/index.php/admin_helloworld/adminhtml_index/index/key/0c82140c8238734651f876e83e2522f5/

我得到如下所示的空白页

谁能说出为什么会这样?

谢谢

更新

阻止文件夹

块文件夹的位置

Helloworld.php

<?php

class Easylife_Helloworld_Block_Helloworld extends Mage_Core_Block_Template
{
    public function Test_Method()
    {
        $result = '';
        $collection = Mage::getModel('helloworld/helloworld')->getCollection()->setOrder('id', 'asc');
        foreach ($collection as $data)
        {
            $result .= $data->getData('firstname') . ' ' . $data->getData('lastname') . ' ' . $data->getData('phone') . '<br />';
        }
        Mage::getSingleton('adminhtml/session')->addSuccess('Success!!');
        return $result;
    }
}

【问题讨论】:

    标签: php xml magento


    【解决方案1】:

    在 controller/Adminhtml 中创建一个名为 HelloworldController.php 的新文件并在该文件中编写代码

    class Easylife_Helloworld_Adminhtml_HelloworldController extends Mage_Adminhtml_Controller_Action{
    
    public function indexAction()
    {
        $Block = $this->getLayout()->createBlock('helloworld/adminhtml_helloworld');
        $this->loadLayout()
            ->_addContent($Block)
            ->renderLayout(); 
    }  }
    

    并在 block/adminhtml/Helloworld/Edit 创建一个文件使用以下代码创建 Form.php 文件

    class Easylife_Helloworld_Block_Adminhtml_Helloworld_Edit_Form extends Mage_Adminhtml_Block_Widget_Form{
     protected function _prepareForm()
     {
        echo "11111111";
       return parent::_prepareForm();
     }}
    

    【讨论】:

    • 对不起@murtuza。您的解决方案不起作用。谢谢
    • 我收到 404 Page not found 错误。谢谢
    • 你创建了adminhtml.xml文件了吗??
    • 不,我还没有创建 adminhtml.xml 文件。谢谢
    • adminhtml.xml 管理员路由所需的文件并在管理员的导航栏中显示您的扩展,因此请创建该文件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-16
    • 1970-01-01
    • 2015-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多