yii model 添加默认值
来源:互联网 发布:淘宝上广告是什么意思 编辑:程序博客网 时间:2024/05/22 15:11
yii model 继承自CActiveRecord
有些字段可能不会出现在表单中,而需要在程序中加入。
如订单编号,时间戳,操作的user_id等等。
以下二种方法:
1,在rules()方法中设定:
public function rules(){// NOTE: you should only define rules for those attributes that// will receive user inputs.return array(array('start, end', 'required'),array('user_id', 'numerical', 'integerOnly'=>true),array('timestamp','default','value'=>date('Y-m-d H:i:s')),// The following rule is used by search().// Please remove those attributes that should not be searched.array('id, start, end, user_id, timestamp', 'safe', 'on'=>'search'),);}
2,在beforeSave()方法中设定:
function beforeSave(){$this->user_id = Yii::app()->user->id;return true;}需要注意的是,beforeSave()方法需要return true,否则不会保存。
- yii model 添加默认值
- yii model 添加默认值
- yii添加字段后model及视图修改
- yii 2.0设置默认值
- yii model操作
- Yii 之 Model 使用方法
- Yii AR Model 查询
- Yii AR Model 查询
- yii model层操作
- Yii AR Model 查询
- Yii model相关操作
- Yii AR Model 查询
- Yii AR Model 查询
- Yii AR Model 查询
- yii学习笔记 - model
- yii 用户管理 model
- Yii AR Model查询
- YII model使用
- java基础pdf上关于死锁演示代码
- InnoDB实现了以下两种类型的行锁
- Android 对话框(Dialog)大全 建立你自己的对话框
- 使用Spring2.5的Autowired实现注释型的IOC 161641
- [iPhone开发]如何编写写一个带多参数的方法
- yii model 添加默认值
- boot system flash bootflash:/cat4500-entservicesk9-mz.122-31.SGA10.bin
- irb(main):040:0> a,b=b,a
- This kind of launch is configured to open the Debug perspective 问题解...
- 如何在Android中添加系统服务
- 写给那些分手之后还留在原地的人:伤感日志
- 数据库连接池
- Ruby 的条件运算符
- 生哥解梦