<?php
|
|
class System_Model_Base{
|
|
protected $db;
|
|
public function __construct(){
|
//从容器中获取注册的DB类
|
$this->db = System_Service_Locator::getInstance()->get('db');
|
}
|
|
/**
|
* 根据条件获取列表
|
* @param array $query [description]
|
* @param array $fields [description]
|
* @param array $sort [description]
|
* @param integer $limit [description]
|
* @param integer $skip [description]
|
* @return [type] [description]
|
*/
|
public function getList($query=array(),$fields=array(),$sort=array(),$limit=0,$skip=0){
|
return $this->db->select($this->table, $query, $fields, $sort, $limit, $skip);
|
}
|
|
/**
|
* 根据条件,获取单条数据
|
* @param array $query [description]
|
* @param array $fields [description]
|
* @return [type] [description]
|
*/
|
public function get($query=array(), $fields=array()){
|
return $this->db->fetchRow($this->table, $query, $fields);
|
}
|
|
/**
|
* 根据条件获取数量
|
* @param array $query [description]
|
* @param integer $limit [description]
|
* @param integer $skip [description]
|
* @return [type] [description]
|
*/
|
public function count($query=array(),$limit=0,$skip=0){
|
return $this->db->count($this->table, $query,$limit, $skip);
|
}
|
|
/**
|
* [add description]
|
*/
|
public function add($data){
|
return $this->db->insert($this->table, $data);
|
}
|
|
/**
|
* 更新
|
* @param [type] $data [description]
|
* @param [type] $query [description]
|
* @return [type] [description]
|
*/
|
public function update($data, $query){
|
return $this->db->update($this->table, $data, $query);
|
}
|
|
/**
|
* 聚合
|
* @param [type] $params [description]
|
* @return [type] [description]
|
*/
|
public function aggregate($params){
|
return $this->db->aggregate($this->table, $params);
|
}
|
|
/**
|
* 删除[禁止删除所有]
|
* @param array $query [description]
|
* @return [type] [description]
|
*/
|
public function delete($query = array()){
|
if(!empty($query))
|
return $this->db->delete($this->table, $query);
|
else
|
return false;
|
}
|
|
|
|
}
|