Hi people,
I have a composite primary key in my DB table, but CArrayDataProvider requires string type for the keyField.
Is there any solution for this?
Thanks.
Hi people,
I have a composite primary key in my DB table, but CArrayDataProvider requires string type for the keyField.
Is there any solution for this?
Thanks.
What exactly in CArrayDataProvider do you want me to check?
The question is how to use an array for the keyField instead of a string…
The code below is just the same as in CActiveDataProvider and solves the problem.
class ExtArrayDataProvider extends CArrayDataProvider {
public $keyField;
protected function fetchKeys(){
$keys=array();
foreach($this->getData() as $i=>$data){
$key=$this->keyField===null ? $data->getPrimaryKey() : $data->{$this->keyField};
$keys[$i]=is_array($key) ? implode(',',$key) : $key;
}
return $keys;
}
}
Shouldn’t it be this way in new version of Yii? Or additional is_array($data) is_object($data) checks needed?
Guru opinion wanted.