Model Update() is not working but Save() is working

Hi Yii members,

I am facing a small problem with a simple update form where user can update his/her email and new password.

system.db.CDbCommand.execute(); this command is not working when i press the submit button… but system.db.CDbCommand.query() works well…

can anyone help me pls ?

my suggestion is , pls use built in functions like model->save(),model->saveByAttribute() …like functions…

thanks rajith for your instant reply. but the problem is i am still using the inbuilt functions and unable to accomplish what i want :(

I have worked with all type of inbuilt funstions… but sadly this time with model->update() its not showing any errors. i tried this way also, model->update(true, array(‘the values i want 2 update’));

i tried all possible values… but still model->update is not working… :(

i tried with this also… var_dump($user->update()) it returns false. when i submit the form… $_POST[‘email’] also contains the value i wanted. but after all $user->update() is still not working.

thanks in advance…

any one thr to throw me a bone ??

CActiveRecord::update() method takes only one parameter (array $attributes=NULL) as per the documentation. Can you please provide the complete usage of the command in your application and show us the exact error that you get.

thanks for you feedback…

this is the code segment that handles update profile.

     if (isset($_POST['Save'])) {


        $user->attributes = $_POST['User'];          


        if ($user->validate(array('email', 'oldPassword', 'newPassword', 'conf_password'))) {


           $newPassword = trim($user->newPassword);


           $user->password = $newPassword;         


           $user->update();


           unset($_POST);


           Yii::app()->user->setFlash('success', 'Profile edited successfully.');


           $controller->redirect($controller->createUrl('default/update'));


        } 


     }

the problem i have is… $user->password is not being updated.

please see the image attached. it wil help you to get an idea. tnx in advance,

This is the image… http://img442.imageshack.us/img442/535/72195239.png

can you also suggest me a better way to do debugging with yii. i am finding it very hard 2 debug…

critical… :(

needed help with this pls

use saveAttributes instead of this, saveAttributes() uses updateByPk() method. Maybe you’ll find it useful…

$user->password = $newPassword;

$user->update();




$user->saveAttributes(array('password'=>$newPassword));



you should really call $user->save(false); instead of $user->update(); to see if it works (please note this will skip validation). Let me know if this works

Also set the following if condition:




if ($user->save(false)) {

unset($_POST);

Yii::app()->user->setFlash('success', 'Profile edited successfully.');

$controller->redirect($controller->createUrl('default/update'));

}



tnx alot… this helped me… :)

welcome :) :)