Archives: 2009 February

CDbExpression

February 23rd, 2009, 4 Comments

Ever want to set an attribute in Active Record with a MySQL function? For instance, often times you need to set an attribute to the well known MySQL function “NOW()”. Most people first attempt this in the following way: <?php $model->createdDate = ‘NOW()'; The above, however, will most definitely not work. Why not? Because Yii […]

Safe attributes tip

February 19th, 2009, No Comments

In my last two posts [1, 2] I explained how to define scenario-based validation rules and safe attributes. Something I have noted is that whenever I end up specifying an attribute as “required” in the validation rules(), I also always end up specifying it as “safe” in safeAttributes() under the same scenario. This got me […]

Safe attribute scenarios

February 17th, 2009, 3 Comments

If you read my last article on validation scenarios then you may understand why in different scenarios you may need different attributes to be required. However you may have noticed a missing link – what if in different scenarios you also need different attributes to be considered as “safe”? If you have no idea about […]

Validation scenarios

February 16th, 2009, 16 Comments

As of Yii 1.0.2 you may now define validation scenarios. This is very useful if for instance you have multiple places in your application that you validate a model, but in each instance you may want different validation rules. For instance, perhaps in your user registration form you want to have the “username”, “email” and […]

Feed

http://php-thoughts.cubedwater.com / 2009 February