I have model that some its field is set "not required", let's say user model have 3 field (login,pass, and birth date).
Login and pass are required field for user model.
And i put all 3 field in form, if i fill all the field only (login) and (pass) filed that saved to database.
While (birth date) always NULL or in MySQL its always set "01-01-1970" regardless what i fill in that field.
Just wondering why yii not save data to database that not set as "required" in model rule?
And there is any solution? except set a default value in database and set (birth date) rule to "require" so if the field is empty, the database/yii will fill it with default value.
Thank You.
Page 1 of 1
"not required" Field in model not saved to database?
#2
Posted 14 March 2010 - 09:01 AM
Even a required field should normally be saved to the database.
Can you post your controller action and the Model class?
Can you post your controller action and the Model class?
#3
Posted 14 March 2010 - 09:46 AM
munemune, on 14 March 2010 - 08:13 AM, said:
...
Just wondering why yii not save data to database that not set as "required" in model rule?
...
Just wondering why yii not save data to database that not set as "required" in model rule?
...
Declare a 'safe' rule (or it won't be massively assigned). BTW any rule will do, e.g 'length'.
See section "Safe Attributes in 1.1"
http://www.yiiframew...uide/form.model
/Tommy
This post has been edited by tri: 14 March 2010 - 09:56 AM
#4
Posted 14 March 2010 - 10:16 AM
tri, on 14 March 2010 - 09:46 AM, said:
Declare a 'safe' rule (or it won't be massively assigned). BTW any rule will do, e.g 'length'.
See section "Safe Attributes in 1.1"
http://www.yiiframew...uide/form.model
/Tommy
See section "Safe Attributes in 1.1"
http://www.yiiframew...uide/form.model
/Tommy
'Safe Attributes' and 'massively assigned' i think i miss those 2 or 4 keyword.
Yes, it's work now.
Thanks for the reply.
Share this topic:
Page 1 of 1

Help













