PHP 클래스 Cml\Model

파일 보기 프로젝트 열기: linhecheng/cmlphp 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$table null | string 表名
$tablePrefix null | string 表前缀

공개 메소드들

메소드 설명
__call ( $dbMethod, $arguments ) : Pdo 当访问model中不存在的方法时直接调用$this->db()的相关方法
__callStatic ( $dbMethod, $arguments ) : Pdo 当访问model中不存在的方法时直接调用相关model中的db()的相关方法
cache ( string $conf = 'default_cache' ) : Redis 获取cache实例
closeDb ( string $conf = 'default_db' ) 当程序连接N个db的时候用于释放于用连接以节省内存
db ( string $conf = '' ) : Pdo 获取db实例
delByColumn ( mixed $val, string $column = null, string $tableName = null, mixed $tablePrefix = null ) : boolean 通过主键删除数据-快捷方法
getByColumn ( mixed $val, string $column = null, string $tableName = null, mixed $tablePrefix = null ) : boolean | array 通过某个字段获取单条数据-快捷方法
getDbConf ( ) : string 获取当前Model的数据库配置串
getInstance ( ) : Model 初始化一个Model实例
getList ( integer $offset, integer $limit = 20, string | array $order = 'DESC', string $tableName = null, mixed $tablePrefix = null ) : array 获取数据列表
getListByPaginate ( integer $limit = 20, string | array $order = 'DESC', string $tableName = null, mixed $tablePrefix = null ) : array 以分页的方式获取数据列表
getMultiByColumn ( mixed $val, string $column = null, string $tableName = null, mixed $tablePrefix = null ) : boolean | array 通过某个字段获取多条数据-快捷方法
getTableName ( ) : string 获取表名
getTotalNums ( null $pkField = null, string $tableName = null, mixed $tablePrefix = null ) : mixed 获取数据的总数
mapDbAndTable ( ) : Pdo 自动根据 db属性执行$this->db(xxx)方法; table/tablePrefix属性执行$this->db('xxx')->table('tablename', 'tablePrefix')方法
set ( array $data, string $tableName = null, mixed $tablePrefix = null ) : integer 增加一条数据-快捷方法
updateByColumn ( integer $val, array $data, string $column = null, string $tableName = null, mixed $tablePrefix = null ) : boolean 通过字段更新数据-快捷方法

메소드 상세

__call() 공개 메소드

当访问model中不存在的方法时直接调用$this->db()的相关方法
public __call ( $dbMethod, $arguments ) : Pdo
$dbMethod
$arguments
리턴 Cml\Db\MySql\Pdo | \Cml\Db\MongoDB\MongoDB | $this

__callStatic() 공개 정적인 메소드

当访问model中不存在的方法时直接调用相关model中的db()的相关方法
public static __callStatic ( $dbMethod, $arguments ) : Pdo
$dbMethod
$arguments
리턴 Cml\Db\MySql\Pdo | \Cml\Db\MongoDB\MongoDB

cache() 공개 메소드

获取cache实例
public cache ( string $conf = 'default_cache' ) : Redis
$conf string 使用的缓存配置;
리턴 Cml\Cache\Redis | \Cml\Cache\Apc | \Cml\Cache\File | \Cml\Cache\Memcache

closeDb() 공개 메소드

当程序连接N个db的时候用于释放于用连接以节省内存
public closeDb ( string $conf = 'default_db' )
$conf string 使用的数据库配置;

db() 공개 메소드

获取db实例
public db ( string $conf = '' ) : Pdo
$conf string 使用的数据库配置;
리턴 Cml\Db\MySql\Pdo | \Cml\Db\MongoDB\MongoDB | \Cml\Db\Base

delByColumn() 공개 메소드

通过主键删除数据-快捷方法
public delByColumn ( mixed $val, string $column = null, string $tableName = null, mixed $tablePrefix = null ) : boolean
$val mixed
$column string 字段名 不传会自动分析表结构获取主键
$tableName string 表名 不传会自动从当前Model中$table属性获取
$tablePrefix mixed 表前缀 不传会自动从当前Model中$tablePrefix属性获取再没有则获取配置中配置的前缀
리턴 boolean

getByColumn() 공개 메소드

通过某个字段获取单条数据-快捷方法
public getByColumn ( mixed $val, string $column = null, string $tableName = null, mixed $tablePrefix = null ) : boolean | array
$val mixed
$column string 字段名 不传会自动分析表结构获取主键
$tableName string 表名 不传会自动从当前Model中$table属性获取
$tablePrefix mixed 表前缀 不传会自动从当前Model中$tablePrefix属性获取再没有则获取配置中配置的前缀
리턴 boolean | array

getDbConf() 공개 메소드

获取当前Model的数据库配置串
public getDbConf ( ) : string
리턴 string

getInstance() 공개 정적인 메소드

初始化一个Model实例
public static getInstance ( ) : Model
리턴 Model | \Cml\Db\MySql\Pdo | \Cml\Db\MongoDB\MongoDB | \Cml\Db\Base

getList() 공개 메소드

获取数据列表
public getList ( integer $offset, integer $limit = 20, string | array $order = 'DESC', string $tableName = null, mixed $tablePrefix = null ) : array
$offset integer 偏移量
$limit integer 返回的条数
$order string | array 传asc 或 desc 自动取主键 或 ['id'=>'desc', 'status' => 'asc']
$tableName string 表名 不传会自动从当前Model中$table属性获取
$tablePrefix mixed 表前缀 不传会自动从当前Model中$tablePrefix属性获取再没有则获取配置中配置的前缀
리턴 array

getListByPaginate() 공개 메소드

以分页的方式获取数据列表
public getListByPaginate ( integer $limit = 20, string | array $order = 'DESC', string $tableName = null, mixed $tablePrefix = null ) : array
$limit integer 每页返回的条数
$order string | array 传asc 或 desc 自动取主键 或 ['id'=>'desc', 'status' => 'asc']
$tableName string 表名 不传会自动从当前Model中$table属性获取
$tablePrefix mixed 表前缀 不传会自动从当前Model中$tablePrefix属性获取再没有则获取配置中配置的前缀
리턴 array

getMultiByColumn() 공개 메소드

通过某个字段获取多条数据-快捷方法
public getMultiByColumn ( mixed $val, string $column = null, string $tableName = null, mixed $tablePrefix = null ) : boolean | array
$val mixed
$column string 字段名 不传会自动分析表结构获取主键
$tableName string 表名 不传会自动从当前Model中$table属性获取
$tablePrefix mixed 表前缀 不传会自动从当前Model中$tablePrefix属性获取再没有则获取配置中配置的前缀
리턴 boolean | array

getTableName() 공개 메소드

获取表名
public getTableName ( ) : string
리턴 string

getTotalNums() 공개 메소드

获取数据的总数
public getTotalNums ( null $pkField = null, string $tableName = null, mixed $tablePrefix = null ) : mixed
$pkField null 主键的字段名
$tableName string 表名 不传会自动从当前Model中$table属性获取
$tablePrefix mixed 表前缀 不传会自动从当前Model中$tablePrefix属性获取再没有则获取配置中配置的前缀
리턴 mixed

mapDbAndTable() 공개 메소드

自动根据 db属性执行$this->db(xxx)方法; table/tablePrefix属性执行$this->db('xxx')->table('tablename', 'tablePrefix')方法
public mapDbAndTable ( ) : Pdo
리턴 Cml\Db\MySql\Pdo | \Cml\Db\MongoDB\MongoDB | \Cml\Db\Base

set() 공개 메소드

增加一条数据-快捷方法
public set ( array $data, string $tableName = null, mixed $tablePrefix = null ) : integer
$data array 要新增的数据
$tableName string 表名 不传会自动从当前Model中$table属性获取
$tablePrefix mixed 表前缀 不传会自动从当前Model中$tablePrefix属性获取再没有则获取配置中配置的前缀
리턴 integer

updateByColumn() 공개 메소드

通过字段更新数据-快捷方法
public updateByColumn ( integer $val, array $data, string $column = null, string $tableName = null, mixed $tablePrefix = null ) : boolean
$val integer 字段值
$data array 更新的数据
$column string 字段名 不传会自动分析表结构获取主键
$tableName string 表名 不传会自动从当前Model中$table属性获取
$tablePrefix mixed 表前缀 不传会自动从当前Model中$tablePrefix属性获取再没有则获取配置中配置的前缀
리턴 boolean

프로퍼티 상세

$table 보호되어 있는 프로퍼티

表名
protected null|string $table
리턴 null | string

$tablePrefix 보호되어 있는 프로퍼티

表前缀
protected null|string $tablePrefix
리턴 null | string