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?
Page 1 of 1
findall() doesn't return a associative array
#2
Posted 11 October 2009 - 02:51 PM
findAll() returns you an array of instances of Auction (ActiveRecord).
You can access the properties/columns of each Auction model by (for example):
And set properties by:
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;
Don't say what you think, think what you say
The problem is communication! Excess of communication!
The problem is communication! Excess of communication!
#3
Posted 11 October 2009 - 02:52 PM
May be you want to re-read this: ActiveRecord
Don't say what you think, think what you say
The problem is communication! Excess of communication!
The problem is communication! Excess of communication!
#4
Posted 11 October 2009 - 03:01 PM
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.
I was just hoping for some sort of convenient toArray() method but i couldn't find it.
#5
Posted 11 October 2009 - 03:54 PM
struvusmaximus: You should have a look at http://php.oregonsta...arrayaccess.php and http://www.php.net/~...rrayAccess.html . That's the technical background for above mentioned stuff.
#6
Posted 22 December 2010 - 08:07 AM
struvusmaximus, on 11 October 2009 - 03:01 PM, said:
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.
I was just hoping for some sort of convenient toArray() method but i couldn't find it.
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.
-------------
m(o_O)m
m(o_O)m
Share this topic:
Page 1 of 1

Help














