ci框架的基本的增删改查

查询

//控制器里面
//接收参数
$id = $this->input->get('id');
//调用模型
$query = $this->ser_toeflreading->getlist($id,$type, $config['per_page'], $this->input->get('per_page'));

//模型ser_toeflreading
function  getlist($id,$type, $perPage = 0, $pageCount = 0){
	$this->db->select('*');
	$this->db->from('ser_toelf_reading');
	if($type == 1){
		$this->db->where('tk_id',$id);
	}else{
		$this->db->where('zt_id',$id);
	}
	//$this->db->order_by("id","desc");
	if ($pageCount == 0) {
		$this->db->limit($perPage, $pageCount * $perPage);
	} else {
		$this->db->limit($perPage, ($pageCount - 1) * $perPage);
	}
	return $this->db->get();
}

增加

//控制器里面
//引入
$this->load->model("ser_toeflreading");
$data = array(
	'tk_id' => $tk_id,
	'zt_id' => $zt_id,
	'title' => $title,
	'image' => $image,
	'content' => $content,
	'sort' => $sort,
);
//调用模型
$this->ser_toeflreading->class_create($data);

//模型ser_toeflreading
function class_create($data){
	return $this->db->insert('ser_toelf_reading', $data);
}

修改

//控制器里面
//接收参数
$id = $this->input->post('id');
//引入
$this->load->model("ser_toeflreading");
$data = array(
	'tk_id' => $tk_id,
	'zt_id' => $zt_id,
	'title' => $title,
	'image' => $image,
	'content' => $content,
	'sort' => $sort,
);
//调用模型
$this->ser_toeflreading->class_update($id, $data);

//模型ser_toeflreading
function class_update($id, $data){
	$this->db->where('id', $id);
	return $this->db->update('ser_toelf_reading', $data);
}

删除

//控制器里面
//接收参数
$id = $this->input->get('id');
$this->load->model('ser_toeflreading');
//调用模型
$this->ser_toeflreading->reading_delete($id);

//模型ser_toeflreading
function reading_delete($id){
	if (!$id) {
		return array();
	}
	return $this->db->delete('ser_toelf_reading', array('id' => $id));
}

获取结果集操作函数

结果集会全部展示
$query ->result_array();

结果集会展示一行
$query->row_array();

猜你喜欢

转载自blog.csdn.net/qq_35960620/article/details/83412004
今日推荐