Ejemplo n.º 1
0
 /**
  * 从配置文件中创建表单
  * @param string $action     表单的url	
  * @param string $configName  配置文件的名字
  * @return Form_Tea $form
  */
 protected static function _createFormConfig($action, $configName)
 {
     $form = new Form_Admin_Tea('tea_form', $action);
     $filename = rtrim(dirname(__FILE__), '/\\') . DS . $configName;
     $form->loadFromConfig(Helper_YAML::load($filename));
     $form->addValidations(Tea::meta());
     //图片的路径
     $form['thumb_filename']->dir = Q::ini('appini/teapics/img_dir');
     //上传图片的限制
     $types = Q::normalize(Q::ini('appini/teapics/upload_allowed_types'));
     $size = intval(Q::ini('appini/teapics/upload_allowed_size') * 1024);
     $dim = Q::ini('appini/teapics/img_pic_width') . 'x' . Q::ini('appini/teapics/img_pic_height');
     $form['postfile']->_tips = sprintf($form['postfile']->_tips, implode('/', $types), $size / 1024, $dim);
     //        茶叶类别
     //       $teatype = new TeaType();
     //       $form['type_id']->items=$teatype->list;
     $form->selectUploadElement('postfile')->uploadAllowedSize($size)->uploadAllowedTypes($types)->enableSkipUpload();
     return $form;
 }
 /**
  * 编辑茶叶属性
  */
 function actionEdit()
 {
     $form = Form_Admin_Tea::createForm(url('tea/edit'));
     $teaId = intval($this->_context->id);
     //查询改记录
     $tea = Tea::find('id =?', $teaId)->query();
     // 导入数据到表单
     $form->import($tea);
     //是否是post提交 及验证通过
     if ($this->_context->isPOST() && $form->validate($_POST)) {
         try {
             //改变表单属性值
             $tea->changeProps($form->values());
             $tea->save();
             return $this->_redirectMessage('恭喜你更新茶叶信息成功', '如果你不做出选择系统将自动跳转', url('tea/index'), 3);
         } catch (QValidator_ValidateFailedException $ex) {
             $form->invalidate($ex);
         }
     }
     $this->_view['tea'] = $tea;
     $this->_view['form'] = $form;
 }