PHP Class Cml\Model

Afficher le fichier Open project: linhecheng/cmlphp Class Usage Examples

Protected Properties

Свойство Type Description
$table null | string 表名
$tablePrefix null | string 表前缀

Méthodes publiques

Méthode 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 méthode

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

__callStatic() public static méthode

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

cache() public méthode

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

closeDb() public méthode

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

db() public méthode

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

delByColumn() public méthode

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

getByColumn() public méthode

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

getDbConf() public méthode

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

getInstance() public static méthode

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

getList() public méthode

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

getListByPaginate() public méthode

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

getMultiByColumn() public méthode

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

getTableName() public méthode

获取表名
public getTableName ( ) : string
Résultat string

getTotalNums() public méthode

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

mapDbAndTable() public méthode

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

set() public méthode

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

updateByColumn() public méthode

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

Property Details

$table protected_oe property

表名
protected null|string $table
Résultat null | string

$tablePrefix protected_oe property

表前缀
protected null|string $tablePrefix
Résultat null | string