<?php
namespace Admin\Controller;
use Think\Controller;
class UserTagController extends CommController {
public function userTag(){
$tagDb=M("Tag");
$count=$tagDb->count();
$Page = new \Think\Page($count,20);
$Page->setConfig('theme','%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%');
$Page->setConfig('prev','上一页');
$Page->setConfig('next','下一页');
$show = $Page->show();
$data=$tagDb->limit($Page->firstRow.','.$Page->listRows)->select();
$this->assign('page',$show);
$this->assign("data",$data);
$this->display();
}
public function deteleTag(){
$tag=I("post.tag_id");
$tagDb=M("Tag");
$result=array("success"=>false,"error"=>"");
$resu=$tagDb->delete($tag);
if($resu){
$result=array("success"=>true,"error"=>"");
}else{
$result=array("success"=>false,"error"=>"delete fail");
}
echo json_encode($result);
}
public function editTag(){
$tag=I("get.tag_id");
$tagDb=M("Tag");
$data=$tagDb->find($tag);
$this->assign("data",$data);
$this->display();
}
public function editSave(){
$tag=I("post.tag_name");
$tagDb=D("Tag");
if ($tagDb->create()){
$result=$tagDb->save();
if($result) {
$this->success('操作成功!',U("UserTag/userTag"));
}else{
$this->error('写入错误!');
}
}else{
$this->error($tagDb->getError());
}
}
function addTag(){
$this->display();
}
public function posttag(){
$tag=I("post.tag_name");
$tagDb=D("Tag");
if ($tagDb->create()){
$result=$tagDb->add();
if($result) {
$this->success('操作成功!',U("UserTag/userTag"));
}else{
$this->error('写入错误!');
}
}else{
$this->error($tagDb->getError());
}
}
}