Hello! Sorry for my English!
In manual im see -
Post::model()->update($attributes,$condition,$params);
In the above, $attributes is an array of column values indexed by column names;
I think this array should look like
$arr['field_name'] => 'new_field_value'
… yes?
I look source code … and what i see?
public function update($attributes=null)
{
if($this->getIsNewRecord())
throw new CDbException(Yii::t('yii','The active record cannot be updated because it is new.'));
if($this->beforeSave())
{
Yii::trace(get_class($this).'.update()','system.db.ar.CActiveRecord');
if($this->_pk===null)
$this->_pk=$this->getPrimaryKey();
$this->updateByPk($this->getOldPrimaryKey(),$this->getAttributes($attributes));
$this->_pk=$this->getPrimaryKey();
$this->afterSave();
return true;
}
else
return false;
}
The main thing we need is there’s this line
$this->updateByPk($this->getOldPrimaryKey(),$this->getAttributes($attributes));
pass to another method. Our array is processed using $ this-> getAttributes ():
Is a part source code:
if(is_array($names))
{
$attrs=array();
foreach($names as $name)
{
if(property_exists($this,$name))
$attrs[$name]=$this->$name;
else
$attrs[$name]=isset($attributes[$name])?$attributes[$name]:null;
}
return $attrs;
}
The main thing we need is
$attrs[$name]=$this->$name;
The new array is formed on the basis of values!
that is -
It was: $arr[‘field_name’] => ‘new_field_value’
It has become: $arr[‘new_field_value’] => NULL
Please explane me about this!