fire
(Fire)
1
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?
binkabir
(Binkabir)
2
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();

zaccaria
(Matteo Falsitta)
3
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.
andy_s
(Arekandrei)
4
Actually there is an update() method, but it doesn’t perform a validation: http://www.yiiframework.com/doc/api/CActiveRecord#update-detail
junxiong
(Garry3peace)
5
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'));