findall() doesn't return a associative array

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?

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;

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.

struvusmaximus: You should have a look at and . That’s the technical background for above mentioned stuff.

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.

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.