Magento Admin Module – Part-3

来源:互联网 发布:php web 应用开发 编辑:程序博客网 时间:2024/05/21 06:54

这篇文章,将要介绍如何创建admin forms

前面的两篇文章,已经详细的介绍了admin grid,这篇文章我们将详细的介绍一下如何在后台创建表单

Forms在magento中可以划分为四个基础部分

1. FORM Container
2. FORM tag
3. FORM Tabs
4. Actual Form Fields

首先,把下面代码放入后台控制器中去,用来显示表单app/code/local/Demo/Simple/controllers/Adminhtml/BlogController.php

public function newAction(){    $this->loadLayout();    $this->_addContent(                $this->getLayout()->createBlock('simple/adminhtml_blog_edit')         )         ->_addLeft(                $this->getLayout()->createBlock('simple/adminhtml_blog_edit_tabs')         );    $this->renderLayout();}
newAction方法中,我们添加了两个Block,一个是内容区域,一个是左边的选项卡区域,这个页面包含两部分,一部分是内容部分$this->_addContent添加的block和左边选项卡,由_addLeft()方法添加的Block


FORM Container
FORM Container(表单容器)

表单容器是什么呢?就像它的名字,在最外层的DIV元素里包含了所有的表单元素和html,为了创建一个表单容器,你需要再app/code/local/Demo/Simple/Block/Adminhtml/Blog创建一个Edit.php文件,在这个文件里创建的类,需要继承

Mage_Adminhtml_Block_Widget_Form_Container
自Mage_Adminhtml_Block_Widget_Form_Container类,把下面代码加入到Edit.php文件中

class Demo_Simple_Block_Adminhtml_Blog_Edit            extends Mage_Adminhtml_Block_Widget_Form_Container{    public function __construct()    {        parent::__construct();                 $this->_objectId = 'id';        $this->_blockGroup = 'simple';        $this->_controller = 'adminhtml_blog';             $this->_updateButton('save', 'label', Mage::helper('simple')->__('Save'));        $this->_updateButton('delete', 'label', Mage::helper('simple')->__('Delete'));        // $this->removeButton('reset');             $this->_addButton('saveandcontinue', array(                'label'    => Mage::helper('adminhtml')->__('Save And Continue Edit'),                'onclick'  => 'saveAndContinueEdit()',                'class'    => 'save',                ),                -100        );    }     public function getHeaderText()    {        return Mage::helper('simple')->__('My Form Container');    }}

让我们来分析一下此文件中的相关代码

getHeaderText(): This function return’s the Text to display as the form header. You can see the form header in the screenshot attached - See more at: http://excellencemagentoblog.com/module-development-series-magento-admin-module-part3#sthash.TslLnlod.dpuf
getHeaderText(): 这个方法在表单的头部显示表单的标题





admin forms
0 0