balaji587
balaji587

Reputation: 69

Update record in model- YII Framework

I have profile page view where user can change the current password. By using findBySql & current session I checked whether the current password is correct. But I don't know how to update the records in the model in yii framework.

Upvotes: 7

Views: 27395

Answers (3)

dev1234
dev1234

Reputation: 5716

You can simply follow this way to update a record in yii.

$user = User::model()->findByPk($userId);
$user->username = 'hello world';
$user->password = 'password';
$user->update();

How to save a new record in yii ?

$user = new User();
$user->username = 'hello world';
$user->password = 'password';
$user->save();

How to delete a record in yii ?

$user = User::model()->findByPk($userId);
$user->delete()

Upvotes: 15

Rémy
Rémy

Reputation: 17

If you want to pop-up message, may you can try with Ajax validation, or Javascript to pop-up a window, after your validation ?

Upvotes: 0

rabidmachine9
rabidmachine9

Reputation: 7985

Please read about yii active record this is a good resource http://www.yiiframework.com/doc/guide/1.1/en/database.ar

It is usually as simple as that:

$user = User::model()->findByPk($userId);
$user->password = 'new_password';
$user->save();

Upvotes: 0

Related Questions