38. 后台模块开发(3)
来源:互联网 发布:数据加密标准des 编辑:程序博客网 时间:2024/04/30 14:28
1.在 Magento 中, 表单(form)可以被分为4个基本部分
1、 表单容器 => FORM Container 2、 表单 => FORM 3、 表单选项卡 => FORM Tabs4、 真实的表单内容 => Actual Form Fields
public function newAction() { $this->loadLayout(); $this->_addContent($this->getLayout()->createBlock('employee/adminhtml_employee_edit')) ->_addLeft('employee/adminhtml_employee_edit_tabs'); $this->renderLayout(); }这里可以直接看出我们在 content 和 left 区域里添加了两个 block, 主要的表单容器被加进了 content 区域,而表单选项卡被加进了 left 区域
2.表单容器
表单容器就是一个大的 div 框, 它包含了表单的所有元素和 html 代码, 为了创建一个容器, 你需要在 Block/Adminhtml/employee/ 文件下创一个 php 文件,并继承了 Mage_Adminhtml_Block_Widget_Form_Container 类我们就把文件名命为: Edit.php
<?phpclass Www_Employee_Block_Adminhtml_Employee_Edit extends Mage_Adminhtml_Block_Widget_Form_Container{ public function __construct() { parent::__construct(); //这个变量被应用于表单的 URL 中, 它包含了表单实体的主键 //拿删除按钮的 URL 来说: 模块/控制器/方法名/$this->_objectid/3 $this->_objectId = 'id'; //这两个变量比较重要,它们就是用来锁定表单选项卡(tabs)文件的, //其路径应该是 {$this->_blockGroup . '/' . $this->_controller . '_' . $this->_mode . '_form'}, //当中的$this->mode含有默认值: 'edit', 那么展现出的路径是: 'employee/adminhtml_employee_edit_form' $this->_blockGroup = 'employee'; $this->_controller = 'adminhtml_employee'; //$this->_updateButton('save','label',Mage::helper('employee')->__('Save')); //$this->_updateButton('delete','label',Mage::helper('employee')->__('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('employee')->__('My Form Container'); }}
3.表单
这个 Block/Adminhtml/Employee/Edit/Form.php 文件包含真实的 <form> 标签, 代码如下:<?phpclass Www_Employee_Block_Adminhtml_Employee_Edit_Form extends Mage_Adminhtml_Block_Widget_Form{ protected function _prepareForm() { $form = new Varien_Data_Form( array( 'id'=>'edit_form', 'action'=>$this->getUrl('*/*/save',array( 'id'=>$this->getRequest()->getParam('id') )), 'method'=>'post', 'enctype'=>'multipart/form-data' ) ); $form->setUseContainer(true); $this->setForm($form); return parent::_prepareForm(); }}
4.表单选项卡
<?phpclass Www_Employee_Block_Adminhtml_Employee_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs{ public function __construct() { $this->setId('employee_tabs'); $this->setDestElementId('edit_form'); $this->setTitle(Mage::helper('employee')->__('Employee Information')); return parent::__construct(); } protected function _beforeToHtml() { $this->addTab('form_section', array( 'label' => Mage::helper('employee')->__('Information'), 'title' => Mage::helper('employee')->__('Employee Information'), 'content' => $this->getLayout() ->createBlock('employee/adminhtml_employee_edit_tab_form') ->toHtml(),) ); return parent::_beforeToHtml(); }}
5.真实的表单内容
<?phpclass Www_Employee_Block_Adminhtml_Employee_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form{ protected function _prepareForm() { $model = Mage::registry('web_data'); $form = new Varien_Data_Form(); $this->setForm($form); $fieldset = $form->addFieldset('employee_form', array( 'legend' => Mage::helper('employee')->__('Employee information') ) ); $fieldset->addField('title', 'text', array( 'label' => Mage::helper('employee')->__('Title'), 'class' => 'required-entry', 'required' => true, 'name' => 'title', ) ); $fieldset->addField('active', 'select', array( 'label' => Mage::helper('employee')->__('Enabled:'), 'name' => 'active', 'class' => 'required-entry', 'required' => true, 'values' => array( array( 'value' => 1, 'label' => Mage::helper('employee')->__('Yes'), ), array( 'value' => 0, 'label' => Mage::helper('employee')->__('No'), ), ), )); $form->setValues($model->getData()); return parent::_prepareForm(); }}
http://www.sunzhenghua.com/magento-admin-module-development-part3-grid-forms-tabs-updatebutton
0 0
- 38. 后台模块开发(3)
- ECSHOP后台开发模块步骤
- ECshop后台开发模块步骤
- MAGENTO 后台模块开发一
- MAGENTO 后台模块开发二
- MAGENTO 后台模块开发三
- MAGENTO 后台模块开发四
- MAGENTO 后台模块开发五
- MAGENTO 后台模块开发六
- MAGENTO 后台模块开发实例
- 34. 后台模块开发(1)
- 35. 后台模块开发(2)
- 39. 后台模块开发(4)
- 40. 后台模块开发(5)
- 41. 后台模块开发(6)
- PHPCMS 后台模块开发之Ajax查询
- bootstrap开发,实现前端后台模块分离
- 门外汉学Web开发-WordPress代码导读(3-Admin后台模块之CSS)
- [zynq] zynq7000开发流程之仿真TestBench
- 近期javaWEB项目总结
- QApplication与QCoreApplication
- 链表的游标实现
- [5]AMQP(高级消息队列协议) ----如何创建自己的SSLContext对象
- 38. 后台模块开发(3)
- 轻量级Android网络请求框架
- Nginx Location配置
- 数组去重,简短而有效的方法
- 阿里云服务器搭建ghost博客之Node环境安装(一)
- 如何构建安全的Android应用
- Android开发学习之使用ViewPager+PagerTabStrip制作可滑动的Tab
- 模拟linkedList添加操作
- Maven创建项目时出现Generating project in Interactive mode就一直卡住的解决方案