修改新闻中心后台栏目添加时的流程处理,修改前台新闻控制器

This commit is contained in:
Li Jianxuan 2012-11-06 03:19:24 +00:00
parent 9f59628516
commit ab243ec84f
3 changed files with 69 additions and 30 deletions

View File

@ -80,21 +80,49 @@ class Admin_NewsController extends Zend_Controller_Action
if($add) if($add)
{ {
if(empty($submit)){
$this->view->categories = $this->getAllcategory();
$this->_helper->viewRenderer('category-add'); $this->_helper->viewRenderer('category-add');
}else{ $this->view->categories = $this->getAllcategory();
$title = $this->_request->getParam('ctitle'); if(empty($submit)){
$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)"; //$this->_helper->viewRenderer('category-add');
if($this->db->exec($sql) > 0) }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->view->error = "请输入标题";
$this->_redirect('/admin/news/catlog'); 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;
} }
} }

View File

@ -13,15 +13,13 @@
<?= $this->partial('news/left.phtml'); ?> <?= $this->partial('news/left.phtml'); ?>
</div> </div>
<div id="rightPanel"> <div id="rightPanel">
<?php if ($this->msg or $this->messages) :?>
<?php if (!empty($this->error)) :?>
<div id="message"> <div id="message">
<?php if ($this->msg) : ?> <?php echo $this->error;?>
<p><?php echo $this->msg; ?></p>
<?php endif; if ($this->messages): foreach($this->messages as $msg): ?>
<p><?php echo $msg; ?></p>
<?php endforeach;endif; ?>
</div> </div>
<?php endif; ?> <?php endif; ?>
<?php if(empty($this->msg)) {?>
<form id="sampleform" method="post" action="#"> <form id="sampleform" method="post" action="#">
<fieldset> <fieldset>
@ -29,7 +27,7 @@
<p> <p>
<label class="required" for="ctitle">栏目标题:</label><br/> <label class="required" for="ctitle">栏目标题:</label><br/>
<input type="text" id="ctitle" class="half" value="" name="ctitle"/> <input type="text" id="ctitle" class="half" value="<?php if(!empty($this->info['title'])) echo $this->info['title'];?>" name="ctitle"/>
</p> </p>
<p> <p>
@ -38,7 +36,16 @@
<option value="0"></option> <option value="0"></option>
<?php if(!empty($this->categories)) :?> <?php if(!empty($this->categories)) :?>
<?php foreach($this->categories as $v) : ?> <?php foreach($this->categories as $v) : ?>
<?php if(empty($this->info['fid'])) {?>
<option value="<?= $v['id'];?>"><?= $v['title'];?></option> <option value="<?= $v['id'];?>"><?= $v['title'];?></option>
<?php }else{
if($this->info['fid'] == $v['id'])
{ ?>
<option value="<?= $v['id'];?>" selected="selected"><?= $v['title'];?></option>
<?php }else{?>
<option value="<?= $v['id'];?>"><?= $v['title'];?></option>
<?php }
}?>
<?php endforeach;?> <?php endforeach;?>
<?php endif; ?> <?php endif; ?>
</select> </select>
@ -46,19 +53,21 @@
<p> <p>
<label class="required" for="ctitle">栏目URL:</label><br/> <label class="required" for="ctitle">栏目URL:</label><br/>
<input type="text" id="url" class="half" value="" name="url"/>(仅小写英文字母与数字) <input type="text" id="url" class="half" value="<?php if(!empty($this->info['url'])) echo $this->info['url'];?>" name="url"/>(仅小写英文字母与数字)
<small>如填写: technology 则前台访问地址为: http://westdc.westgis.ac.cn/news/technology </small> <small>如填写: technology 则前台访问地址为: http://westdc.westgis.ac.cn/news/technology </small>
</p> </p>
<p> <p>
<label class="required" for="keyword">关键字:</label><br/> <label class="required" for="keyword">关键字:</label><br/>
<input type="text" id="keyword" class="half" value="" name="keyword"/> <input type="text" id="keyword" class="half" value="<?php if(!empty($this->info['keywords'])) echo $this->info['keywords'];?>" name="keyword"/>
<small>e.g. 高程,气象,地理</small> <small>e.g. 高程,气象,地理</small>
</p> </p>
<p> <p>
<label class="required" for="discript">描述:</label><br/> <label class="required" for="discript">描述:</label><br/>
<textarea id="discript" class="medium half" name="description"></textarea> <textarea id="discript" class="medium half" name="description">
<?php if(!empty($this->info['description'])) echo $this->info['description'];?>
</textarea>
<small>80个汉字以内不能使用折行</small> <small>80个汉字以内不能使用折行</small>
</p> </p>
@ -69,4 +78,11 @@
</fieldset> </fieldset>
</form> </form>
<?php }else{ ?>
<div class="alert alert-success">
<a data-dismiss="alert" class="close">×</a>
<?php echo $this->msg ?>
</div>
<script language="javascript">setTimeout("self.location='<?php echo $this->jump_url ?>'",3000);</script>
<?php } ?>
</div> </div>

View File

@ -1,13 +1,13 @@
<?php <?php
class NewsController extends Zend_Controller_Action class NewsController extends Zend_Controller_Action
{ {
private $limit=10; private $limit=10;
function preDispatch() function preDispatch()
{ {
$this->view->config = Zend_Registry::get('config'); $this->view->config = Zend_Registry::get('config');
$this->db=Zend_Registry::get('db'); $this->db=Zend_Registry::get('db');
$this->messenger=$this->_helper->getHelper('FlashMessenger');
$this->view->messages = $this->messenger->getMessages();
} }
function indexAction() function indexAction()
@ -116,11 +116,6 @@ class NewsController extends Zend_Controller_Action
$sql .= " LEFT JOIN news_category type ON arc.typeid=type.id"; $sql .= " LEFT JOIN news_category type ON arc.typeid=type.id";
$sql .= " LEFT JOIN users u ON arc.userid=u.id"; $sql .= " LEFT JOIN users u ON arc.userid=u.id";
$sql .= " WHERE arc.is_pub>0 AND arc.ts_published<'now()' AND arc.id=$archive"; $sql .= " WHERE arc.is_pub>0 AND arc.ts_published<'now()' AND arc.id=$archive";
/*
$sql = "SELECT arc.* FROM news_archives arc";
$sql .= " LEFT JOIN news_category type ON arc.typeid=type.id";
$sql .= " WHERE arc.is_pub>0 AND ts_published<'$time' AND arc.id=$archive";
*/
$rs = $this->db->query($sql); $rs = $this->db->query($sql);
$row = $rs->fetch(); $row = $rs->fetch();