Files
spacestation/admin/core/HD_Controller.php
T
2024-05-26 16:00:30 +08:00

128 lines
3.0 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: linfan
* Date: 2018/11/3
* Time: 21:23
*/
defined('BASEPATH') or exit('No direct script access allowed');
abstract class HD_Controller extends CI_Controller
{
public $uid, $user_name, $role;
public $data = array(), $if_ajax = false;
public $city_lists = [430, 350]; //开发城市湖南 福建
public function __construct()
{
parent::__construct();
$this->if_ajax = $this->input->is_ajax_request();
}
/*
* * * 编码规则 * * *
*
* 默认实现抽象方法
*
* 默认操作前缀相同的方法权限保持一致,若不一致应分开成两个controller
*
* 根据需要添加方法 [操作]_[名称]
* 如 状态 get_status|edit_status
*
* 除private方法外不允许有其他方式的命名
*
* 操作id: index-1 lists-2 get-3 add-4 edit-5 del-6 batch-7 export-8
*
*/
//首页信息
public abstract function index();
//数据列表
public abstract function lists();
//展示单条数据
public abstract function get();
//添加单条数据
public abstract function add();
//编辑单条数据
public abstract function edit();
//删除单条数据
public abstract function del();
//批量操作(默认修改状态)
public abstract function batch();
//导出数据列表
public abstract function export();
//返回视图页面
protected function show_view($view, $refresh = false)
{
$this->load->vars($this->data);
if ($refresh) {
$this->load->view('refresh');
$this->load->view('bread');
}
$this->load->view($view);
$this->load->view('snav');
if ($this->uid == SUPER_ADMIN) {
debug_sql();
}
return true;
}
/**
* 返回json数据
* @param int $code
* @param string $msg
* @param string $url ('#/app/jjd/list')
* @param int $wait
* @return bool
*/
protected function show_json($code = 0, $msg = 'success', $url = '', $wait = 0)
{
header('Content-Type:application/json; charset=utf-8');
echo json_encode(array('data' => $this->data, 'code' => $code, 'msg' => $msg, 'url' => $url, 'wait' => $wait), JSON_UNESCAPED_UNICODE);
if ($this->uid == SUPER_ADMIN) {
debug_sql();
}
return false;
}
/**
* 获取可以管理的城市
* @param null $def
* @return mixed
*/
protected function city_ary($def = null)
{
$this->load->model("sys/sys_city_model", 'city_model');
if (!is_null($def)) {
return '';
}
$where = array('status' => 1);
$orderby = "id desc";
$select = "city_id, name";
$map_city = $this->city_model->map('city_id', 'name', $where, $orderby, 0, 0, $select);
return $map_city;
}
}