完善栏目删除时的操作,自动整理左右值

This commit is contained in:
Li Jianxuan 2014-03-03 04:07:34 +00:00
parent c9b2e843b7
commit b81b97f910
3 changed files with 853 additions and 795 deletions

View File

@ -1,127 +1,151 @@
<?php <?php
/** /**
* Zend Framework (http://framework.zend.com/) * Zend Framework (http://framework.zend.com/)
* *
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository * @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License * @license http://framework.zend.com/license/new-bsd New BSD License
*/ */
namespace Admin\Controller; namespace Admin\Controller;
use Zend\Mvc\Controller\AbstractActionController; use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel; use Zend\View\Model\ViewModel;
use Zend\View\Model\JsonModel; use Zend\View\Model\JsonModel;
use Sookon\Helpers\View as view; use Sookon\Helpers\View as view;
class CategoryController extends AbstractActionController class CategoryController extends AbstractActionController
{ {
public $ViewModel; public $ViewModel;
function __construct($db = NULL) function __construct($db = NULL)
{ {
$this->ViewModel = new ViewModel(); $this->ViewModel = new ViewModel();
} }
public function indexAction() public function indexAction()
{ {
$ac = $this->params()->fromRoute('ac'); $ac = $this->params()->fromRoute('ac');
$record = new \Sookon\Article\Category; $record = new \Sookon\Article\Category;
$this->ViewModel->setVariable('categorys',$record->GetFullCategory()); $this->ViewModel->setVariable('categorys',$record->GetFullCategory());
$this->ViewModel->setTemplate('layout/admin/category/list'); $this->ViewModel->setTemplate('layout/admin/category/list');
return $this->ViewModel; return $this->ViewModel;
return $this->ViewModel; return $this->ViewModel;
} }
public function addAction() public function addAction()
{ {
$submit = $this->params()->fromPost('submit'); $submit = $this->params()->fromPost('submit');
$category = new \Sookon\Article\Category; $category = new \Sookon\Article\Category;
$this->ViewModel->setVariable('ptype',$category->ptype); $this->ViewModel->setVariable('ptype',$category->ptype);
$this->ViewModel->setVariable('categories',$category->GetFullCategory()); $this->ViewModel->setVariable('categories',$category->GetFullCategory());
$this->ViewModel->setVariable('deepField',$category->DeepTitle);
if(empty($submit) || !$this->getRequest()->isXmlHttpRequest())
return $this->ViewModel; if(empty($submit) || !$this->getRequest()->isXmlHttpRequest())
return $this->ViewModel;
$status = $category->add($category->getParam());
$status = $category->add($category->getParam());
if($status !== true)
{ if($status !== true)
return new JsonModel(array('error'=>$status)); {
}else{ return new JsonModel(array('error'=>$status));
return new JsonModel(array('success'=>1)); }else{
} return new JsonModel(array('success'=>1));
} }
}
public function editAction()
{ public function editAction()
$submit = $this->params()->fromPost('submit'); {
$id = $this->params()->fromRoute('id'); $submit = $this->params()->fromPost('submit');
$ac = $this->params()->fromRoute('ac'); $id = $this->params()->fromRoute('id');
if(!is_numeric($id) || $id<1) $ac = $this->params()->fromRoute('ac');
{ if(!is_numeric($id) || $id<1)
view::Post($this,"参数错误",-1); {
return $this->ViewModel; view::Post($this,"参数错误",-1);
} return $this->ViewModel;
}
if($ac == 'content')
{ if($ac == 'content')
$this->ViewModel->setTemplate("admin/category/add"); {
$this->ViewModel->setTemplate("admin/category/add");
$category = new \Sookon\Article\Category;
$this->ViewModel->setVariable('categories',$category->GetFullCategory()); $category = new \Sookon\Article\Category;
$this->ViewModel->setVariable('data',$category->fetch($id)); $this->ViewModel->setVariable('categories',$category->GetFullCategory());
$this->ViewModel->setVariable('data',$category->fetch($id));
if(empty($submit) || !$this->getRequest()->isXmlHttpRequest())
return $this->ViewModel; if(empty($submit) || !$this->getRequest()->isXmlHttpRequest())
return $this->ViewModel;
$status = $category->add($category->getParam(),$id);
$status = $category->add($category->getParam(),$id);
if($status !== true)
{ if($status !== true)
return new JsonModel(array('error'=>$status)); {
}else{ return new JsonModel(array('error'=>$status));
return new JsonModel(array('success'=>1)); }else{
} return new JsonModel(array('success'=>1));
} }
}
if($ac == "moveup")
{ if($ac == "moveup")
$category = new \Sookon\Article\Category; {
$status = $category->move("up",$id); $category = new \Sookon\Article\Category;
$status = $category->move("up",$id);
if(is_array($status))
{ if(is_array($status))
$this->ViewModel->setVariable('moved',$status); {
$this->ViewModel->setTemplate('layout/admin/category/moved'); $this->ViewModel->setVariable('moved',$status);
return $this->ViewModel; $this->ViewModel->setTemplate('layout/admin/category/moved');
}else{ return $this->ViewModel;
view::Post($this,$status,-1); }else{
return $this->ViewModel; view::Post($this,$status,-1);
} return $this->ViewModel;
} }
}
if($ac == "movedown")
{ if($ac == "movedown")
$category = new \Sookon\Article\Category; {
$status = $category->move("down",$id); $category = new \Sookon\Article\Category;
$status = $category->move("down",$id);
if(is_array($status))
{ if(is_array($status))
$this->ViewModel->setVariable('moved',$status); {
$this->ViewModel->setTemplate('layout/admin/category/moved'); $this->ViewModel->setVariable('moved',$status);
return $this->ViewModel; $this->ViewModel->setTemplate('layout/admin/category/moved');
}else{ return $this->ViewModel;
view::Post($this,$status,-1); }else{
return $this->ViewModel; view::Post($this,$status,-1);
} return $this->ViewModel;
} }
}
}
} }
public function delAction()
{
$id = (int)$this->params()->fromRoute('id');
if(empty($id) || $id<=0)
{
return view::Post($this,"参数错误",-1);
}
$category = new \Sookon\Article\Category;
$status = $category->del($id);
if($status === TRUE)
{
return view::Post($this,"删除成功!",-1);
}else{
if(is_string($status))
return view::Post($this,$status,-1);
return view::Post($this,"删除失败!",-1);
}
}
}

View File

@ -39,7 +39,9 @@
<td><?= $v['ptype'] ?></td> <td><?= $v['ptype'] ?></td>
<td><?= date("Y-m-d H:i",strtotime($v['ts_created'])) ?></td> <td><?= date("Y-m-d H:i",strtotime($v['ts_created'])) ?></td>
<td> <td>
<a href="" onclick="return confirm('是否确定删除?')"><span class="glyphicon glyphicon-trash"></span></a> <a href="<?= $this->url('admin',array('controller'=>'category','action'=>'del','ac'=>'content','id'=>$v['id'])) ?>" onclick="return confirm('是否确定删除?')">
<span class="glyphicon glyphicon-trash"></span>
</a>
<a href="<?= $this->url('admin',array('controller'=>'category','action'=>'edit','ac'=>'content','id'=>$v['id'])) ?>"><span class="glyphicon glyphicon-pencil"></span></a> <a href="<?= $this->url('admin',array('controller'=>'category','action'=>'edit','ac'=>'content','id'=>$v['id'])) ?>"><span class="glyphicon glyphicon-pencil"></span></a>
<a href="<?= $this->url('admin',array('controller'=>'category','action'=>'edit','ac'=>'moveup','id'=>$v['id'])) ?>"> <a href="<?= $this->url('admin',array('controller'=>'category','action'=>'edit','ac'=>'moveup','id'=>$v['id'])) ?>">
<span class="glyphicon glyphicon-arrow-up"></span> <span class="glyphicon glyphicon-arrow-up"></span>

File diff suppressed because it is too large Load Diff