//排序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;//打印出來是不是刪除當(dāng)前的這個欄目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 ;// 設(shè)置附件上傳大小
$upload->exts=array('jpg', 'gif', 'png', 'jpeg');// 設(shè)置附件上傳類型
$upload->rootPath='./';
$upload->savePath='./Public/Uploads/'; // 設(shè)置附件上傳目錄
$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 ;// 設(shè)置附件上傳大小
$upload->exts=array('jpg', 'gif', 'png', 'jpeg');// 設(shè)置附件上傳類型
$upload->rootPath='./';
$upload->savePath='./Public/Uploads/'; // 設(shè)置附件上傳目錄
$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();
}
}
?>