Esempio n. 1
0
 /**
  * 添加新闻类别的属性
  *
  */
 function getSorts()
 {
     $sort = NewSort::find('parent_id =1')->setColumns('id,name')->asArray()->getAll();
     $arr = array('id' => 0, 'name' => '请选择类别');
     array_unshift($sort, $arr);
     $sort = Helper_Array::toHashmap($sort, 'id', 'name');
     return $sort;
 }
 /**
  * 删除新闻类别
  *
  */
 function actionDelete()
 {
     //得到要删除的id 号
     $array_id = (array) $this->_context->id;
     //是否选择了一条记录
     if (!empty($array_id)) {
         NewSort::meta()->destroyWhere('id IN (?)', $array_id);
     }
     return $this->_redirectMessage('删除新闻类别成功', '如果你不做出选择系统将自动跳转', url('newsort/index'), 3);
 }
Esempio n. 3
0
 /**
  * 从配置文件中生成新闻表单
  *
  * @param string $action 表单的url
  * @param string $config 配置文件的名字
  * @return object 表单对象
  */
 static function _createFormConfig($action, $config)
 {
     $form = new Form_Admin_News('create_news', $action);
     $fileName = dirname(__FILE__) . DS . "{$config}";
     $form->loadFromConfig(Helper_YAML::load($fileName));
     $form->addValidations(News::meta());
     //查询类别
     $sort = NewSort::find()->order('name ASC')->getAll();
     $sort = Helper_Array::toHashmap($sort, 'id', 'name');
     $form['newbody']['sort_id']->items = $sort;
     return $form;
 }
Esempio n. 4
0
 /**
  * 从配置文件中生成新闻表单
  *
  * @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('news', url('news/create'));
     if ($this->_context->isPOST() && $form->validate($_POST)) {
         //是否post提交及通过验证
         try {
             $news = new News($form->values());
             $user = $this->_app->currentUser();
             $news['user_id'] = $user['id'];
             //				$news['newsort']['news_count']=
             //更新该栏目下的新闻条数
             $newSort = NewSort::meta()->find('id =?', $form['sort_id']->value)->query();
             $newSort->news_count++;
             $newSort->save();
             //保存更新
             $news->save();
             return $this->_redirectMessage('恭喜你发布新闻成功', '如果你不做出选择系统将自动跳转', url('news/index'), 3);
         } catch (QValidator_ValidateFailedException $ex) {
             $form->invalidate($ex);
         }
     }
     $this->_view['form'] = $form;
 }