qc.ifish7.com/Application/Admin/Controller/LinkController.class.php

83 lines
2.4 KiB
PHP

<?php
namespace Admin\Controller;
use Think\Controller;
class LinkController extends AdminController{
public function __construct(){
parent::__construct();
$this->table=D("Link");
$this->cat=M("link_cat")->order("sort asc")->select();
}
//
public function index(){
$catid=I("get.catid",0,"intval");
if($catid){
$where["catid"]=I("get.catid",0,"intval");
}
$data=$this->table->relation(true)->where($where)->order("sort asc,id asc")->select();
$this->assign('data', $data);
$this->display($type);
}
//
public function add(){
if(IS_POST){
$data=$this->table->create();
if (!$data){//验证
$this->error($this->table->getError());
}
$id=$this->table->add($data);
D("UserLog")->add("add",$this->table->getTableName(),$id);
$this->success($id);
}else{
$this->catid=$catid;
$this->pubid=make_pubid();
$this->display();
}
}
public function editor(){
if(IS_POST){
$data=$this->table->create();
if (!$data){//验证
$this->error($this->table->getError());
}
$this->table->save($data);
D("UserLog")->add("update",$this->table->getTableName(),$data[id]);
$this->success($data);
}else{
$id=I("get.id",0,"int");
$r=$this->table->find($id);
$this->assign("r",$r);
$this->display();
}
}
//
public function delete(){
$ids=I("ids");
if(!$ids){
$this->error('请选择信息!');
return false;
}
if(is_array($ids)){
foreach($ids as $id){
$this->table->delete($id);
}
}else{
$this->table->delete($ids);
}
D("UserLog")->add("delete",$this->table->getTableName(),$ids);
$this->success("删除成功");
}
//字段排序
public function sort(){
$ids=I("id");
$sort=I("sort");
foreach($ids as $key=>$id){
$data['id']=(int)$id;
$data['sort']=(int)$sort[$key];
$this->table->save($data);
}
$this->success("排序更改成功");
}
}