[英]Magento Admin Layout and Template
我是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>
該文件的位置
我正在嘗試瀏覽以下網址
我得到如下的空白頁
誰能說出為什么會這樣嗎?
謝謝
UPDATE
阻止文件夾
阻止文件夾的位置
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;
}
}
在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();
}}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.