模型抽象类,无法直接实例化
namespace ginkgo;
abstract class Model {
// 属性
protected $config = array();
protected $obj_request;
protected $obj_builder;
protected $table;
protected $className;
private $configThis = array(
'type' => 'mysql',
'host' => '',
'name' => '',
'user' => '',
'pass' => '',
'charset' => 'utf8',
'prefix' => 'ginkgo_',
'debug' => false,
'port' => 3306,
);
private $obj_db;
// 方法
public __construct( [ array $config ] )
public __call( string $method, mixed $params ) : mixed
protected m_init()
protected config( array $config )
protected validate( mixed $data [, mixed $validate [, string $scene [, array $only [, array $remove [, array $append ]]]]] ) : mixed
protected realClassProcess() : string
}
- | 权限 | 类型 | 描述 |
---|---|---|---|
属性 | - | - | - |
$obj_request |
protected | object | 请求实例 |
$obj_builder |
protected | object | SQL 语句构造器实例 |
$table |
protected | string | 表名 |
$className |
protected | string | 类名 |
$config |
protected | array | 配置 |
$configThis |
private | array | 默认配置 |
$obj_db |
private | object | 数据库实例 |
方法 | - | - | - |
__construct() | public | 构造函数 | |
__call() | public | 魔术调用 | |
m_init() | protected | 模型初始化 | |
config() | protected | 配置 | |
validate() | protected | 验证 | |
realClassProcess() | protected | 类名处理 |
$config
配置,$configThis
默认配置protected static $config;
private static $configThis;
结构
名称 | 类型 | 默认 | 描述 |
---|---|---|---|
type | string | mysql | 数据库类型 |
host | string | 服务器 | |
name | string | 数据库名 | |
user | string | 用户名 | |
pass | string | 密码 | |
charset | string | utf8 | 字符编码 |
prefix | string | ginkgo_ | 表名前缀 |
debug | bool | false | 是否打开数据库调试 |
port | int | 3306 | 端口 |
__construct()
构造函数protected function __construct( [ array $config ] ) : object
参数
config
配置参数返回
__call()
魔术调用自动调用 ginkgo\Db 的方法
protected function __call( string $method, mixed $params ) : mixed
参数
method
方法名,必须为数据库实例支持的方法params
参数返回
m_init()
模型初始化protected function m_init()
参数
返回
config()
配置protected function config( array $config )
参数
config
配置参数返回
validate()
验证protected function validate( mixed $data [, mixed $validate [, string $scene [, array $only [, array $remove [, array $append ]]]]] ) : mixed
参数
data
待验证数据validate
验证器名称
支持两种类型:为字符串时表示验证器名称,为数组时表示验证规则,为空时自动查找验证器
scene
验证场景
only
仅验证指定规则remove
移除指定规则append
追加验证规则返回
realClassProcess()
类名处理protected function realClassProcess() : string
参数
返回