Magento Admin Module – Part-3

这篇文章,将要介绍如何创建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
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值