/** * 删除新闻类别 * */ function actionDelete() { //得到要删除的id 号 $array_id = (array) $this->_context->id; //是否选择了一条记录 if (!empty($array_id)) { Articlesorts::meta()->destroyWhere('id IN (?)', $array_id); } return $this->_redirectMessage('删除文章类别成功', '如果你不做出选择系统将自动跳转', url('articlesort/index'), 3); }
/** * 从配置文件中生成新闻表单 * * @param string $action 表单的url * @param string $config 配置文件的名字 * @return object 表单对象 */ static function _createFormConfig($id, $action, $config) { $form = new Form_Admin_Sort($id, $action); $fileName = dirname(__FILE__) . DS . "{$config}"; $form->loadFromConfig(Helper_YAML::load($fileName)); //查询父类的id号 if ('article' == $id) { $form->addValidations(Articlesorts::meta()); $form['name']->_label = '文章分类名称'; $parent = Articlesorts::find("name =?", '茶与文化')->setColumns('id')->asArray()->query(); } else { $form->addValidations(NewSort::meta()); $parent = NewSort::find("name =?", '业界动态')->setColumns('id')->asArray()->query(); } $form['parent_id']->value = $parent['id']; return $form; }
/** * 发布新闻 * */ function actionCreate() { $this->_viewname = 'edit'; $form = Form_Admin_News::createForm('article', url('article/create')); if ($this->_context->isPOST() && $form->validate($_POST)) { //是否post提交及通过验证 try { $news = new Articles($form->values()); $user = $this->_app->currentUser(); $news['user_id'] = $user['id']; //更新该栏目下的新闻条数 $newSort = Articlesorts::meta()->find('id =?', $form['sort_id']->value)->query(); $newSort->news_count++; $newSort->save(); //保存更新 $news->save(); return $this->_redirectMessage('发表文章成功', '如果你不做出选择系统将自动跳转', url('article/index'), 3); } catch (QValidator_ValidateFailedException $ex) { $form->invalidate($ex); } } $this->_view['form'] = $form; }