Files
sentcms/app/controller/admin/Link.php

98 lines
2.5 KiB
PHP

<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\admin;
use app\controller\Admin;
use app\model\Link as LinkModel;
class Link extends Admin{
/**
* @title 友链列表
*/
public function index(LinkModel $link){
if ($this->request->isAjax()) {
$res = $link->paginate(25, false, array(
'query' => $this->request->param()
));
$data = $res->toArray();
$this->data['data'] = $data;
return $this->data;
}
}
/**
* @title 添加友链
*/
public function add(LinkModel $link){
if ($this->request->isPost()) {
$data = $this->request->post();
$result = $link->save($data);
if (false !== $result) {
return $this->success('成功添加', url('/admin/link/index'));
}else{
return $this->error($this->model->getError());
}
}else{
$info['appid'] = rand_string(10, 1); //八位数字appid
$info['appsecret'] = rand_string(32); //32位数字加字母秘钥
$this->data['data'] = array(
'info' => $info
);
return $this->data;
}
}
/**
* @title 编辑友链
*/
public function edit(LinkModel $link){
if ($this->request->isPost()) {
$data = $this->request->post();
if (!isset($data['id']) || !$data['id']) {
return $this->error('非法操作!');
}
$result = $link->exists(true)->save($data);
if (false !== $result) {
return $this->success('修改成功', url('/admin/link/index'));
}else{
return $this->error($this->model->getError());
}
}else{
$info = $link->where('id', $this->request->param('id'))->find();
$this->data['template'] = "add";
$this->data['data'] = array(
'info' => $info
);
return $this->data;
}
}
/**
* @title 删除友链
*/
public function del(LinkModel $link){
$ids = $this->request->param('ids', 0);
if(!$ids){
return $this->error('非法操作!');
}else{
$ids = \explode(",", $ids);
}
$result = $link->where('id', 'IN', $ids)->delete();
if(false !== $result){
return $this->success('删除成功!');
}else{
return $this->error('删除失败!');
}
}
}