YII2.0框架(二) 模型类参考yii\base\Model
来源:互联网 发布:淘宝网 情趣内衣 模特 编辑:程序博客网 时间:2024/06/06 07:24
摘自 http://www.yiichina.com/doc/api/2.0/yii-base-model
$model = new Admin();
$rules = $model->rules(); //验证规则
/**
* [
* // built-in "required" validator
* [['username', 'password'], 'required'],
* // built-in "string" validator customized with "min" and "max" properties
* ['username', 'string', 'min' => 3, 'max' => 12],
* // built-in "compare" validator that is used in "register" scenario only
* ['password', 'compare', 'compareAttribute' => 'password2', 'on' => 'register'],
* // an inline validator defined via the "authenticate()" method in the model class
* ['password', 'authenticate', 'on' => 'login'],
* // a validator of class "DateRangeValidator"
* ['dateRange', 'DateRangeValidator'],
* ];
*/
$scenarios = $model->scenarios(); //场景列表和对应的活动属性
/**
* [
* 'scenario1' => ['attribute11', 'attribute12', ...],
* 'scenario2' => ['attribute21', 'attribute22', ...],
* ...
* ]
*/
$formName = $model->formName(); //默认当前模型类名: Admin
$attributes = $model->attributes(); //默认当前模型所有非公有静态属性
$attributeLabels = $model->attributeLabels(); //属性标签,用于页面展示
$attributeHints = $model->attributeHints(); //属性提示,用于页面展示
$validate = $model->validate(); //验证表单
$getValidators = $model->getValidators(); //所有的声明在[[rules()]]的验证器
$getActiveValidators = $model->getActiveValidators(); //当前场景的验证器
$isAttributeRequired = $model->isAttributeRequired('name'); //属性是否必须
$isAttributeSafe = $model->isAttributeSafe('name'); //属性是否安全
$isAttributeActive = $model->isAttributeActive('name'); //属性是否在当前场景
$getAttributeLabel = $model->getAttributeLabel('name'); //指定属性的标签
$getAttributeHint = $model->getAttributeHint('name'); //指定属性的提示
$hasErrors = $model->hasErrors('name'); //是否有错误
$getErrors = $model->getErrors(); //所有属性或单个属性的错误
$getFirstErrors = $model->getFirstErrors(); //所有属性的第一条错误
/**
* Array
* (
* [name] => Name cannot be blank.
* [phone] => Phone cannot be blank.
* [password] => Password cannot be blank.
* [repassword] => Repassword cannot be blank.
* )
*/
$getFirstError = $model->getFirstError('name');//属性的第一条错误: Name cannot be blank.
$model->addError('name', '名称不能为空!'); //给属性添加错误
$getNameErrors = $model->getErrors('name');
/**
* Array
* (
* [0] => Name cannot be blank.
* [1] => 名称不能为空!
* )
*/
$model->clearErrors('name'); //清除错误
$generateAttributeLabel = $model->generateAttributeLabel('name'); // 通过给定的属性名生成一个友好的属性标签
$getAttributes = $model->getAttributes(['name', 'phone']); // 获得属性值
$model->setAttributes(['name'=>'jack', 'phone'=>'1500']); // 批量设置属性值
$getAttributes = $model->getAttributes(['name', 'phone']); // 获得属性值
$getScenario = $model->getScenario(); // 当前场景
// $model->setScenario('add'); //设置当前场景
$safeAttributes = $model->safeAttributes(); // 当前场景的安全属性
/**
* Array
* (
* [0] => name
* [1] => phone
* [2] => password
* [3] => repassword
* )
*/
$activeAttributes = $model->activeAttributes(); // 当前场景的验证属性
$load = $model->load($post); // 将输入的数据填入模型
$loadMultiple = Admin::loadMultiple([$model], $post); // 从终端用户向模型中填入数据
$validateMultiple = Admin::validateMultiple([$model]); // 验证多种模型
$fields = $model->fields(); // 字段列表
/** Array
* (
* [name] => name
* [phone] => phone
* [password] => password
* [repassword] => repassword
* )
*/
$getIterator = $model->getIterator(); // 迭代器
- YII2.0框架(二) 模型类参考yii\base\Model
- YII2.0框架(一) 请求处理类参考yii\web\Request
- yii2.0 安装问题:Unknown Method – yii\base\UnknownMethodException
- Yii2—模型(Model)
- Yii2 - 06模型(Model)
- Yii2—模型(Model)
- 【Yii系列】Yii2.0基础框架
- yii2 Unknown Method – yii\base\UnknownMethodException
- Yii2基类控制器文件分析(yii\base\Controller.php)创建动作执行动作
- YII2.0框架(三) 缓存机制yii\caching\Cache
- YII2.0框架(四) 数据库操作yii\db\Commond
- Yii2详解Model类
- 安装yii2时出错 Invalid Parameter – yii\base\InvalidParamException
- yii框架之gii创建数据表对应的model类
- YII2.0的yii文件
- Yii的Model ( 模型)创建及使用
- yii的Model ( 模型)创建及使用
- Yii的Model ( 模型)创建及使用
- EffectiveJava第二章
- 微信小程序支付功能 C# .NET开发
- eclipse快捷
- php获取各种时间戳
- Android获取图片的宽度和高度
- YII2.0框架(二) 模型类参考yii\base\Model
- 串口--异步通信和同步通信深入理解
- loadrunner-事务
- Openvswitch原理与代码分析(2):用户态流表flow table的操作
- 简单Tab的制作
- Spring (一)
- hive常用函数总结
- Bash Shell 学习记录(二)
- C++:利用模板类进行若干排序算法