随笔分类 - YII学习
YII学习使用的一些心得
摘要:开启 ajax 验证view 层beginWidget('CActiveForm', array( 'id'=>'user-form', 'enableAjaxValidation'=>true, 'enableClientValidation'=>true, 'focus'=>array($model,'firstName'),)); ?>然后在控制器里面public function actionCreate(){ $model=new User;
阅读全文
摘要:今天使用model rules 里面的 on 发现死活不起作用,后来搜索发现 需要设置model 实例的scenario 属性才能起作用,不知道为什么。//控制器内 $model = new User();$model->scenario = 'add';//模型内public function rules() { // NOTE: you should only define rules for those attributes that // will receive user inputs. return array( array('username, pa
阅读全文
摘要:使用 DAO 可以使用 $command->getText(); 方法 来获取SQL语句,不过好像没有绑定的参数的值另外可以使用日志功能 来在页面下方输出 'log'=>array( 'class'=>'CLogRouter', 'routes'=>array( array( 'class'=>'CFileLogRoute', 'levels'=>'error, warning', ), array( 'class'
阅读全文
摘要:多缓存配置array( 'components'=>array( .. 'MemCache'=>array( 'class'=>'CMemCache', //下面的配置保证YII不对存储的key 和数据进行 hash 和序列化操作 'hashKey'=>false, 'keyPrefix'=>'', 'serializer'=>false, ...
阅读全文
摘要:有的字段需要设置默认值,这个时候,我们可以使用 rule 规则来实现比如添加时间 addtime ,使用系统时间的时候,在model 层的 rules 方法里面 添加array('addtime','default','value'=>time()),另外 也可以使用网上搜的 beforeSave public function beforeSave() { $this->addtime = time(); return true;}注意:此两者都需要在 rules 规则里面取消 addtime 字段的 required,目前对 YI
阅读全文

浙公网安备 33010602011771号