Hello,
I’m getting some values from an Active Record, however, I need them straight as an array and not directly as an Active Record object.
Therefore, I’ve remembered to use the CHtml::listData to transform it to what I need to, a bi-dimensional array.
The problem is that it will just pass one of the values to the array. Why?
Code with example of what I’m trying to do below:
<?php
$categories = PageCategory::model()->findAllByAttributes( array('page_id'=>1) );
foreach($categories as $c)
echo $c->page_id . ' - '. $c->category_id.'<br />';
/* OUTPUT
1 - 1
1 - 2
*/
// DOES NOT WORK
$categories = CHtml::listData($categories, 'page_id', 'category_id');
echo '<pre>';print_r($categories);echo '</pre>';
/* OUTPUT
Array
(
[1] => 2
)
SHOULD PASS SOMETHING LIKE
Array
(
[1] => 1
[1] => 2
)
*/
?>