Layne
(Petrbuchyn)
1
Hi all!
Does Yii give opportunity to define default model attribute values on different scenarios?
For example, when I do something like this in controller’s action:
$model=new Call('successCall');
I want attribute $model->callStatus to have default value ‘success’.
Can I do it, and, if I can, how?
Thanks in advance, and please sorry for my English.
Raoul
(Manu34)
2
Hi Layne,
maybe you could use the CDefaultValueValidator together with the ‘on’ parameter in the rules() method in your model.
public function rules(){
return array(
array('my_attribute', 'default', 'value' => 'default value on success', 'on' => 'successCall'),
array('my_attribute', 'default', 'value' => 'default value on failures', 'on' => 'failureCall'),
// etc ....
);
}
I think this should work.
If you set the scenario in the constructor, then you could maybe also overload the init() method and initialize your attribute.
