我是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>
此档案的位置
我正在尝试浏览以下网址
我得到如下的空白页面
有人能说为什么会这样吗?
由于
更新
阻止文件夹
块文件夹的位置
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;
}
}
答案 0 :(得分:0)
在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();
}}