PHP Class Cml\Model

Show file Open project: linhecheng/cmlphp Class Usage Examples

Protected Properties

Property Type Description
$table null | string 表名
$tablePrefix null | string 表前缀

Public Methods

Method Description
__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 通过字段更新数据-快捷方法

Method Details

__call() public method

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

__callStatic() public static method

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

cache() public method

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

closeDb() public method

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

db() public method

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

delByColumn() public method

通过主键删除数据-快捷方法
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属性获取再没有则获取配置中配置的前缀
return boolean

getByColumn() public method

通过某个字段获取单条数据-快捷方法
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属性获取再没有则获取配置中配置的前缀
return boolean | array

getDbConf() public method

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

getInstance() public static method

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

getList() public method

获取数据列表
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属性获取再没有则获取配置中配置的前缀
return array

getListByPaginate() public method

以分页的方式获取数据列表
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属性获取再没有则获取配置中配置的前缀
return array

getMultiByColumn() public method

通过某个字段获取多条数据-快捷方法
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属性获取再没有则获取配置中配置的前缀
return boolean | array

getTableName() public method

获取表名
public getTableName ( ) : string
return string

getTotalNums() public method

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

mapDbAndTable() public method

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

set() public method

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

updateByColumn() public method

通过字段更新数据-快捷方法
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属性获取再没有则获取配置中配置的前缀
return boolean

Property Details

$table protected property

表名
protected null|string $table
return null | string

$tablePrefix protected property

表前缀
protected null|string $tablePrefix
return null | string