In my controller I have actionCreate to save model to DB. This works fine.
Now I try to set some attributes manually after I received them from my form:
But somehow I end up having the model saved two times in my DB. The problem is $model->status=0; because without it is saved only once. So what is wrong with "$model->status=0;"?
Thanks for your help
I think the problem is not here. Maybe you have switch on ajax validate on your form and the framework will send the requiest to server for validating the form by ajax automaticly.
Have a look your form and try to switch off ajax validation.
Or use firebug to see what is going on.
Thanks elbek, you were right! In my CActiveForm Widget I had the parameter enableAjaxValidation set to true.
I discovered seconds before your answer that my assumption cannot be true as by another test all of a sudden I got the model saved four times!
Do you know why this multiple saving is happening with enableAjaxValidation?
Maybe because on ajax request the validation is passed and model is successfully saved? If you use an ajax validation, you should end an application after a validation:
Thanks for the answer. Never thought of this as I’m still learning all this AJAX stuff.