diff --git a/application/admin/controllers/NewsController.php b/application/admin/controllers/NewsController.php index 46968a08..b6d666b4 100644 --- a/application/admin/controllers/NewsController.php +++ b/application/admin/controllers/NewsController.php @@ -80,21 +80,49 @@ class Admin_NewsController extends Zend_Controller_Action if($add) { + $this->_helper->viewRenderer('category-add'); + $this->view->categories = $this->getAllcategory(); if(empty($submit)){ - $this->view->categories = $this->getAllcategory(); - $this->_helper->viewRenderer('category-add'); - }else{ - $title = $this->_request->getParam('ctitle'); - $url = $this->_request->getParam('url'); - $keyword = $this->_request->getParam('keyword'); - $description = $this->_request->getParam('description'); - $fid = $this->_request->getParam('fid'); - $sql="insert into news_category (title,keywords,description,url,fid,display) values ('$title','$keyword','$description','$url','$fid',1)"; - if($this->db->exec($sql) > 0) + //$this->_helper->viewRenderer('category-add'); + }else{ + $data = array(); + + $data['title'] = $this->_request->getParam('ctitle'); + $data['url'] = $this->_request->getParam('url'); + $data['keywords'] = $this->_request->getParam('keyword'); + $data['description'] = $this->_request->getParam('description'); + $data['fid'] = $this->_request->getParam('fid'); + $data['display'] = 1; + + $this->view->info = $data; + + if(empty($data['title'])) { - $this->messenger->addMessage('提示信息:栏目添加成功!'); - $this->_redirect('/admin/news/catlog'); + $this->view->error = "请输入标题"; + return true; + } + + if(empty($data['url'])) + { + $this->view->error = "请输入栏目连接,如http://westdc.westgis.ac.cn/news/notice,则只需要输入notice"; + return true; + } + + if(!preg_match("/^[a-z]+$/",$data['url'])) + { + $this->view->error = "url格式不正确,仅允许26个小写字母"; + return true; + } + + if($this->db->insert("news_category",$data)) + { + $this->view->msg = '提示信息:栏目添加成功!'; + $this->view->jump_url = '/admin/news/catlog'; + return true; + }else{ + $this->view->error = "添加失败,请重试"; + return true; } } diff --git a/application/admin/views/scripts/news/category-add.phtml b/application/admin/views/scripts/news/category-add.phtml index 609ffb58..5095ce8c 100644 --- a/application/admin/views/scripts/news/category-add.phtml +++ b/application/admin/views/scripts/news/category-add.phtml @@ -13,15 +13,13 @@ = $this->partial('news/left.phtml'); ?>
msg; ?>
-messages): foreach($this->messages as $msg): ?> - - +error;?>