$table
$table :
Model Class
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Role_model extends CI_Model
{
private $table = 'role';
public function __construct()
{
parent::__construct();
}
/**
* 获取角色列表
*/
public function getRoleList($where = array(), $select = '*', $limit = 10, $start = 0)
{
$param = $this->_getWhere($where);
$this->db->select($select);
$this->db->where($param);
$this->db->order_by('roleId', 'asc')->limit($limit, $start);
return $this->db->get($this->table)->result_array();
}
/**
* 添加
*/
public function insertData($roleData)
{
$bool = $this->db->insert($this->table, $roleData);
$res = $bool ? $this->db->insert_id() : false;
return $res;
}
/**
* 修改
*/
public function updateData($roleData, $roleId = 0)
{
$this->db->where('roleId', $roleId);
$query = $this->db->update($this->table, $roleData);
return $query ? $roleId : false;
}
/**
* 查询单条数据
*/
public function getRoleRow($roleId = 0)
{
$this->db->where('roleId', $roleId);
return $this->db->get($this->table)->row_array();
}
/**
* 检查角色名称是否存在
*/
public function checkUnique($roleName, $roleId = 0)
{
$this->db->from($this->table);
$this->db->where('roleName', $roleName);
if (!empty($roleId))
{
$this->db->where('roleId !=', $roleId);
}
$result = $this->db->get();
return $result->row_array();
}
/**
* 获取总条数
*/
public function getRowCount($where = array())
{
$param = $this->_getWhere($where);
$this->db->where($param);
return $this->db->count_all_results($this->table);
}
/**
* 查询条件
*/
public function _getWhere($where = array())
{
$param = array();
if (!empty($where['roleName']))
{
$param['roleName like'] = '%' . strval($where['roleName']) . '%';
}
return $param;
}
/**
* 删除
* @return bool
* */
public function delete( $roleId )
{
$this->db->where('roleId', $roleId);
$query = $this->db->delete( $this->table );
return $query;
}
}