I’am just trying the Yii framework and i have the following “problem”.
i have a Auction model and when i want to get all the records in the mysql database using:
$auctions = Auction::model()->findAll();
I get a array with lots of data (CActiveRecordMetaData Object,CMysqlColumnSchema Objec etc.) and somewhere in this nested array structure is my data.
How do i get this data as a associative array?
cyberpol
(Cyberpol 777)
2
findAll() returns you an array of instances of Auction (ActiveRecord).
You can access the properties/columns of each Auction model by (for example):
foreach ($auctions as $auction){
$someProperty = $auction->property;
}
And set properties by:
$auction->property = $someProperty;
cyberpol
(Cyberpol 777)
3
May be you want to re-read this: ActiveRecord
Tnx, i made a foreach loop that calls getattributes on the objects and fills a array.
I was just hoping for some sort of convenient toArray() method but i couldn’t find it.
sven.q
(Svenwin)
5
szako
(Sacoka)
6
I understand what you wanted. I needed something like in_array() on a resultset. (Only one column’s values were needed)
$attributeCodes = CHtml::listData(Attribute::model()->findAll(array('select' => 'code, id')), 'id', 'code');
This gave me the associated array.
The solution is also written here.
mikl
(Mike)
7
Since Yii version 1.1.5 you can use the index property of CdbCriteria to get your result records indexed by any column you like.