码迷,mamicode.com
首页 > 其他好文 > 详细

CI框架通用Model类封装

时间:2014-12-01 00:36:34      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   sp   on   div   art   

 1 <?php
 2 class CommonModel extends CI_Model{
 3     function __construct(){
 4         parent::__construct();
 5         $this->load->database();
 6     }
 7     public function search($table,$where){
 8         $this->db->where($where);
 9         $query=$this->db->get($table);
10         return $query->result_array();
11     }
12     public function pageGet($table,$where=null,$start=1,$limit=10){
13         $result=$this->db->get($table)->result_array();
14         return $result;
15     }
16     public function findOne($table,$idmap){
17         $this->db->where($idmap[‘key‘],$idmap[‘value‘]);
18         $this->db->select(‘*‘);
19         $query=$this->db->get($table);
20         $one=$query->row_array();
21         return $one;
22     }
23 
24     public function addData($table,$data){
25         return $this->db->insert($table,$data);
26     }
27 
28     public function modify($table,$data,$where){
29         $this->db->where($where);
30         return $this->db->update($table,$data);
31     }
32 
33     public function remove($idmap,$table){
34         if(is_array($idmap[‘value‘])){
35             $ids=implode($id, ‘,‘);
36             $this->db->where($idmap[‘key‘].‘ in‘,‘(‘.$idmap[‘value‘].‘)‘);
37             $this->db->delete($table,array($idmap[‘key‘].‘ in‘,‘(‘.$idmap[‘value‘].‘)‘));
38         }else{
39             $this->db->delete($table,array($idmap[‘key‘],$idmap[‘value‘]));
40         }
41     }
42 }

 

CI框架通用Model类封装

标签:style   blog   io   ar   color   sp   on   div   art   

原文地址:http://www.cnblogs.com/codetown/p/4133952.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!