Hello guys,
I want to get a list of values from an ActiveRecord. Something like this:
array(145, 243, 987)
How can I accomplish this ?
Kind Regards,
Marian
Hello guys,
I want to get a list of values from an ActiveRecord. Something like this:
array(145, 243, 987)
How can I accomplish this ?
Kind Regards,
Marian
You should try one of the CActiveRecord::findAll* methods and then populate an array with the attribute you want.
Yeah, that’s what I did. I find kinda sad that Yii doesn’t have such a basic function…
You may use CHtml::listData or CDbCommand appropriate methods as well.
CHtml::listData generates the data suitable for list-based HTML elements. I don’t need that. I need just an array of values. Of course I can use CHtml::listData like to buid something like this: array(id => value), but this ain’t right. Yii needs something like this: values list.
And I don’t want to use CdbCommand. I want to use AR… It works perfect in Django.
hi Marian
after findAll you can use php array_map function:
$list = array_map(function($e) {return $e->ColumnName;}, $models);