67 lines
2.1 KiB
PHP
67 lines
2.1 KiB
PHP
<?php
|
|
namespace Admin\Controller;
|
|
use Think\Controller;
|
|
class TableController extends AdminController{
|
|
public function __construct(){
|
|
parent::__construct();
|
|
$this->table=D("table");
|
|
}
|
|
public function index(){
|
|
$data=$this->table->order('sort asc')->select();
|
|
$this->assign("data",$data);
|
|
$this->display();
|
|
}
|
|
public function add(){
|
|
if(IS_POST){
|
|
if (!$this->table->create()){//验证
|
|
$this->error($this->table->getError());
|
|
}
|
|
$table_id=$this->table->data_add();
|
|
D("UserLog")->add("add",$this->table->getTableName(),$table_id);
|
|
$this->success($table_id);
|
|
}else{
|
|
$this->display();
|
|
}
|
|
}
|
|
public function editor(){
|
|
if(IS_POST){
|
|
if (!$this->table->create()){//验证
|
|
$this->error($this->table->getError());
|
|
}
|
|
|
|
$result=$this->table->data_editor();
|
|
if(!$result){
|
|
$this->error($this->table->getError());
|
|
}
|
|
D("UserLog")->add("update",$this->table->getTableName(),$result[table_id]);
|
|
$this->success($data);
|
|
|
|
}else{
|
|
$table_id=I("get.table_id",0,"int");
|
|
$r=$this->table->find($table_id);
|
|
$this->assign("r",$r);
|
|
$this->display();
|
|
}
|
|
}
|
|
//删除数据表
|
|
public function delete(){
|
|
$table_id=I("table_id",0,'intval');
|
|
$result=$this->table->data_delete($table_id);
|
|
if(!$result){
|
|
$this->error($this->table->getError());
|
|
}
|
|
D("UserLog")->add("delete",$this->table->getTableName(),$table_id);
|
|
$this->success("删除成功");
|
|
}
|
|
//字段排序
|
|
public function sort(){
|
|
$ids=I("table_id");
|
|
$sort=I("sort");
|
|
foreach($ids as $key=>$id){
|
|
$data['table_id']=(int)$id;
|
|
$data['sort']=(int)$sort[$key];
|
|
$this->table->save($data);
|
|
}
|
|
$this->success("排序更改成功");
|
|
}
|
|
} |