Esempio n. 1
0
 public function actionAdd()
 {
     $add = new NewsModel();
     $add->title = $_POST['title'];
     $add->text = $_POST['text'];
     $add->date = date('Y-m-d H:i:s');
     $view = new View();
     if ($add->insert()) {
         $view->result = 'Новость успешно добавлена';
     }
     $view->display('add.php');
 }
Esempio n. 2
0
 /**
  * 添加新闻
  *
  */
 public function addAction()
 {
     // 实例化Model
     $news = new NewsModel();
     // 处理post数据
     if ($this->getRequest()->isPost()) {
         // 获取所有post数据
         $pdata = $this->getAllPost();
         // 处理图片等特殊数据
         $imageInfo = Tools_help::upload('img', 'news');
         if (!empty($imageInfo)) {
             $pdata['img'] = $imageInfo;
         } else {
             unset($pdata['img']);
         }
         // 验证
         $result = $news->validation->validate($pdata, 'add');
         $news->parseAttributes($pdata);
         // 通过验证
         if ($result) {
             // 入库前数据处理
             $pdata['dateline'] = Tools_help::htime($news->dateline);
             $pdata['updatetime'] = Tools_help::htime($news->updatetime);
             // Model转换成数组
             $data = $news->toArray($pdata);
             $result = $news->insert($data);
             if ($result) {
                 // 提示信息并跳转到列表
                 Tools_help::setSession('Message', '添加成功!');
                 $this->redirect('/backend/news/index');
             } else {
                 // 验证失败
                 $this->_view->assign('ErrorMessage', '添加失败!');
                 $this->_view->assign("errors", $news->validation->getErrorSummary());
             }
         } else {
             // 验证失败
             $this->_view->assign('ErrorMessage', '添加失败!');
             $this->_view->assign("errors", $news->validation->getErrorSummary());
         }
     }
     // 格式化表单数据
     // 模版分配数据
     $this->_view->assign("news", $news);
     $this->_view->assign("pageTitle", '添加新闻');
 }
Esempio n. 3
0
 public function actionAll()
 {
     $article = new NewsModel();
     $article->title = 'ывапыв';
     $article->text = 'пыврыв!';
     $article->insert();
     die;
     /*
             $news=News::getAll();
             $view=new View();
     
             //$view->assign('items',$news);
             //$view->assign('items',$news);
             $view->items=$news;
     
             //foreach ($view as $k=>$v){
             //    echo $k;
             //}
     
     
             $view->display('news/all.php');*/
 }