how do I update a single attributes valie?

Hi thre, I can not find in the documentation how to update just a single value:

Ie:

$mymodel= MyModel::model()->find(‘name=:name’, array(’:name’=>‘fire’));

[size=2] $mymodel->lastname=‘mylastname’;[/size]

[size=2][/size][size=2] $mymodel->update();[/size]

[size=2][/size]this doesnt work… what can I do?

hello, did you created any method "update()" in your MyModel class?

if NO?

then use the save() method that came with the CActiveRecord

eg.

myModel=MyModel::model()->find (‘name=:name’,array(’:name’=>‘fire’));

$myModel->lastname=‘MyLastName’;

$myModel->save();

:rolleyes:

try




$mymodel->lastname='mylastname';

$mymodel->save();



or


$mymodel->update(array('lastname'=>'mylastname'));

Save is saving the model as it is (with your modification), update expect a list of attributes to update.

The method update() exists.

Actually there is an update() method, but it doesn’t perform a validation: http://www.yiiframework.com/doc/api/CActiveRecord#update-detail

what about saveAttributes(), it can save certain fields only but it also doesn’t do validation

for example


$mymodel= MyModel::model()->find('name=:name', array(':name'=>'fire'));

$mymodel->lastname='mylastname';

$mymodel->saveAttributes(array('lastname'));