//排序list栏目
public function catesort(){
//dump($_POST);
$cate=D('cate');
foreach ($_POST as $id => $sort) {
$cate->where("id=$id")->setField('sort',$sort);
}
$this->success('排序成功',U('cate_list',array("sort"=>1)),3);
}
//删除栏目
public function cate_del($id){
$cate = D('cate');//实例化一个对象,把实例化好的对象赋值给$column
//echo $id; die;//打印出来是不是删除当前的这个栏目id
if($cate->delete($id)){
$this->success('删除成功',U(cate_list),0);
}else{
$this->error('删除失败!');
}
}
//添加
public function cate_add(){
$cate=D('cate');
if(IS_POST){
$data['catename'] = I('catename');
$data['content'] = I('content');
$data['keywords'] =I('keywords');
$data['des'] = I('des');
$data['type'] = I('type');
$data['parenid'] = I('parenid');
if($_FILES['pic']['tmp_name'] !=''){
$upload = new \Think\Upload();// 实例化上传类
$upload->maxSize=3145728 ;// 设置附件上传大小
$upload->exts=array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$upload->rootPath='./';
$upload->savePath='./Public/Uploads/'; // 设置附件上传目录
$info=$upload->uploadOne($_FILES['pic']);
if(!$info) {// 上传错误提示错误信息
$this->error($upload->getError());
}else{// 上传成功 获取上传文件信息
$data['pic']=$info['savepath'].$info['savename'];
}
}
if ($cate->create($data)){
if ($cate->add($data)){
$this->success('栏目添加成功',U('cate_list'),3);
}else {
$this->error('抱歉栏目添加失败');
}
}else {
$this->error($cate->getError());
}
return;
}
$cateres=$cate->catetree();//指向一个方法---》model,分类树
$this->assign('cateres',$cateres);//分配出去
$this->display();
}
//修改方法
public function cate_edit($id){
$cate=D('cate');
if(IS_POST){
$data['id'] = I('id');
$data['catename'] = I('catename');
$data['content'] = I('content');
$data['keywords'] =I('keywords');
$data['des'] = I('des');
$data['type'] = I('type');
$data['parenid'] = I('parenid');
if($_FILES['pic']['tmp_name'] !=''){
$upload = new \Think\Upload();// 实例化上传类
$upload->maxSize=3145728 ;// 设置附件上传大小
$upload->exts=array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$upload->rootPath='./';
$upload->savePath='./Public/Uploads/'; // 设置附件上传目录
$info=$upload->uploadOne($_FILES['pic']);
if(!$info) {// 上传错误提示错误信息
$this->error($upload->getError());
}else{// 上传成功 获取上传文件信息
$data['pic']=$info['savepath'].$info['savename'];
}
}
if ($cate->create($data)){
if (false!==$cate->save($data)){
$this->success('栏目修改成功',U('cate_list'),3);
}else {
$this->error('抱歉栏目修改失败');
}
}else {
$this->error($cate->getError());
}
return;
}
$catea=$cate->find($id);
$cates=$cate->catetree();//指向一个方法---》model,分类树
$this->assign('cates',$cates);//分配出去
$this->assign('catea',$catea);//分配出去
$this->display();
}
}
?>
网友评论