saegeek
(Abdallah)
1
Hi,
Is it possible to retrieve an array of the db elements using a CDbCriteria ?
My code is the following:
$dbCriteria = new CDbCriteria;
$dbCriteria->params = array(':id'=>$id[0]);
I mean an simple array like this (not an object) :
array(
[0] => array('id'=>0,'name'=>'foobar'),
[1] => array('id'=>1,'name'=>'foo')
);
rwz
(Rz)
2
I just use a loop.
$criteria = new CDBCriteria;
$criteria->params = array(':id'=>$id[0]);
$data = YourModel::model()->findAll($criteria);
$return = array();
foreach($data as $row)
{
$return[] = $row->attributes;
}
ivica
(Ivica Nedeljkovic)
3
You could also use: CHtml::listData() method, to get array of data.
saegeek
(Abdallah)
4
I think there is a need of a new independent function here because CHtml::listData() require some values for HTML list options :
public static array listData(array $models, string $valueField, string $textField, string $groupField='')
using a loop is not so clean