$instance
$instance : object
Reference to the CI singleton
Application Controller Class
This class object is the super class that every library in CodeIgniter will be assigned to.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Linkadmin extends CI_Controller
{
private static $data;
public function __construct()
{
parent::__construct();
$this->load->model('Public_model', 'public');
$this->load->model('Linkadmin_model', 'linkadmin');
$this->load->model('Webcommon_model', 'common');//积分流水表
self::$data['header'] = $this->public->header('栏目管离');
self::$data['left'] = $this->public->leftmenu('linkadmin');
self::$data['footer'] = $this->public->footer();
// $this->public->authentication();
self::$data['title'] = '栏目管理';
$this->public->authentication();
// $userAuthority = $this->include->checkAuthority('linkadmin');
// if($userAuthority !== false)
// {
// echo $userAuthority;exit;
// }
}
/**
* 菜单列表页
* */
public function index()
{
if ($_GET) {
//获取Datatables发送的参数 必要
$draw = $_GET['draw'];//这个值作者会直接返回给前台
//排序
$order_column = $_GET['order']['0']['column'];//那一列排序,从0开始
$order_dir = $_GET['order']['0']['dir'];//ase desc 升序或者降序
//拼接排序sql
$orderSql = "";
//搜索
$search = $_GET['search']['value'];//获取前台传过来的过滤条件
//分页
$start = $_GET['start'];//从多少开始
$length = $_GET['length'];//数据长度
$limitSql = '';
$limitFlag = isset($_GET['start']) && $length != -1;
if ($limitFlag) {
$limitSql = " LIMIT " . intval($start) . ", " . intval($length);
}
//定义查询数据总记录数sql
$sumSql = "SELECT count(*) as sum FROM linkadmin as a WHERE a.deleteFlag=0";
//定义过滤条件查询过滤后的记录数sql
$sumSqlWhere = " and a.linkName LIKE '%" . $search . "%'";
//条件过滤后记录数 必要
$recordsFiltered = 0;
//表的总记录数 必要
$recordsTotal = 0;
//查询总数
$total = $this->common->getsqldata($sumSql);
// var_dump($total);exit;
$recordsTotal = $total[0]['sum'];
$totalResultSql = "SELECT a.* FROM linkadmin as a WHERE a.deleteFlag=0";
if (strlen($search) > 0) {
//记录总数
$total = $this->common->getsqldata($sumSql . $sumSqlWhere);
$recordsFiltered = $total[0]['sum'];
$list = $this->common->getsqldata($totalResultSql . $sumSqlWhere . $orderSql . $limitSql);
} else {
//记录总数
$recordsFiltered = $recordsTotal;
$list = $this->common->getsqldata($totalResultSql . $orderSql . $limitSql);
}
header("Content-Type:text/html;charset=utf-8");
$list = $this->catsort($list, 0, 1);
exit(json_encode(array(
"draw" => intval($draw),
"recordsTotal" => intval($recordsTotal),
"recordsFiltered" => intval($recordsFiltered),
"data" => $list
)));
} else {
$this->load->view('admincp/linkadmin/linkadminlist', self::$data);
}
}
/**
* 增加/编辑页
*/
public function edit()
{
$linkadmininfo = array();
$linkId = $this->input->get_post('linkId');
$linkadmin = $this->linkadmin->getAlladminlink();
$list = $this->catsort($linkadmin, 0, 1);
$linkId = intval($linkId);
if (!empty($linkId)) {
$linkadmininfo = $this->linkadmin->getLinkAdminRow($linkId);
}
//var_dump(self::$roledefault);
//print_r($list);exit;
self::$data['linkadmininfo'] = !empty($linkadmininfo) ? $linkadmininfo : array();
self::$data['linkadmin'] = $list;
//echo $linkId;exit;
self::$data['linkId'] = $linkId;
$this->load->view('admincp/linkadmin/linkadmininfo', self::$data);
}
/**
* 递归查询栏目(树状形展示)
* @param array $arr
* @param int $parentId 父级id
* @param $lev int 等级数
* */
function catsort($arr, $parentId = 0, $lev = 0)
{
static $list = array();
static $num = 0;
foreach ($arr as $v) {
if ($v['parentId'] == $parentId) {
$num = 0;
$v['lev'] = $lev;
$list[] = $v;
$this->catsort($arr, $v['linkId'], $lev + 1);
}
}
return $list;
}
/**
* 修改添加栏目
* */
public function updateData()
{
// var_dump($_POST);exit;
$param = array();
$res = array('err' => 1, 'msg' => '系统错误', 'data' => array());
$linkId = $this->input->post('linkId');
$param['linkId'] = $linkId;
$param['linkName'] = $this->input->post('linkName');
$param['linkUrl'] = $this->input->post('linkUrl');
$param['keyWord'] = $this->input->post('keyWord');
$param['parentId'] = $this->input->post('parentId');
$param['displayOrder'] = $this->input->post('displayOrder');
$param['fa'] = $this->input->post('fa');
if (!empty($linkId))//修改
{
$bool = $this->linkadmin->updateLinkadmin($linkId, $param);
// echo $this->db->last_query();exit;
$res['msg'] = $bool ? '修改成功' : '修改失败';
$res['err'] = $bool ? 0 : 1;
} else//添加
{
$bool = $this->linkadmin->addLinkadmin($param);
$res['msg'] = $bool ? '添加成功' : '添加失败';
$res['err'] = $bool ? 0 : 1;
$param['linkId'] = $bool;
}
$url = base64_encode($this->config->item('base_url') . '/admincp/linkadmin');
$referer = base64_decode($url);
echo $this->public->message($res['msg'], $referer, 0, array(), array('keyword' => 'linkadmin'));
exit;
}
/**
* 检查栏目名称和关键字唯一
* */
public function ajaxcheck()
{
$res = array('status' => 0);
$linkId = $this->input->post('linkId');
$title = $this->input->post('title');
$type = $this->input->post('type');
$data = $this->linkadmin->checkUnique(trim($title), $type, $linkId);
if (!empty($data)) {
$res['status'] = 1;
}
echo json_encode($res);
}
/**
* 删除栏目
* */
public function ajaxchang()
{
$res = array('err' => 1, 'msg' => '系统错误', 'data' => array());
$linkId = $this->input->get_post('linkId');
$childlink = $this->linkadmin->getLinkadmin(0, $linkId);
if (!empty($childlink))//有子级不能删
{
$res['msg'] = '该栏目下有子级栏目不能删除';
echo json_encode($res);
exit;
}
$bool = $this->linkadmin->delete($linkId);
$res['err'] = $bool ? 0 : 1;
$res['msg'] = $bool ? '删除成功' : '删除失败';
echo json_encode($childlink);
exit;
}
}