Exemplo n.º 1
0
 static function createForm($id, $action)
 {
     $form = new Form_Admin_Links($id, $action);
     $form->add(QForm::ELEMENT, 'name', array('_ui' => 'textbox', '_label' => '友情链接名称', '_req' => true, '_tips' => '友情链接的网站名'))->add(QForm::ELEMENT, 'url', array('_ui' => 'textbox', '_label' => '网站地址', '_req' => true, '_tips' => '友情链接网站的网址'))->add(QForm::ELEMENT, 'link_id', array('_ui' => 'hidden'))->add(QForm::ELEMENT, 'img', array('_ui' => 'admin_picpreview', '_label' => '已上传图片', 'attr' => array('dir' => 'links')))->add(QForm::ELEMENT, 'ico', array('_ui' => 'upload', '_label' => '上传图标', '_tips' => ''))->add(QForm::ELEMENT, 'order_num', array('_ui' => 'textbox', '_label' => '排序', 'value' => 0));
     $form->addValidations(Links::meta());
     //上传图片的限制
     $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['ico']->_tips = sprintf($form['ico']->_tips, implode('/', $types), $size / 1024, $dim);
     $form->selectUploadElement('ico')->uploadAllowedSize($size)->uploadAllowedTypes($types)->enableSkipUpload();
     //表单验证规则
     return $form;
 }
 /**
  * 编辑新闻
  *
  */
 function actionEdit()
 {
     $link_id = intval($this->_context->link_id);
     //创建表单
     $form = Form_Admin_Links::createForm('links', url('links/edit'));
     $link = Links::find('link_id =?', $link_id)->query();
     $form->import($link);
     //是否是post提交 及通过验证
     if ($this->_context->isPOST() && $form->validate($_POST)) {
         try {
             $link->changeProps($form->values());
             $link->save();
             return $this->_redirectMessage('编辑友情链接成功', '如果你不做出选择系统将自动跳转', url('links/index'), 3);
         } catch (QValidator_ValidateFailedException $ex) {
             $form->invalidate($ex);
         }
     }
     $this->_view['form'] = $form;
     $this->_viewname = 'edit';
 }