yii - ActiveRecord result return by findAll method needs in different format -


i executed following statement $posts = post::model()->with(array( 'category', 'member', 'profile' ))->findall();

i printed $posts in log file. got following result.

 array (     [0] => post object         (             [_new:cactiverecord:private] =>              [_attributes:cactiverecord:private] => array                 (                     [id] => 1                     [post_text] => sales needs increase end of month. don't wnat reason behind this.                     [member_id] => 2                     [category_id] => 3                     [published] => 0                     [draft] => 1                     [date_added] => 2014-04-06                 )              [_related:cactiverecord:private] => array                 (                     [category] => category object                         (                             [_new:cactiverecord:private] =>                              [_attributes:cactiverecord:private] => array                                 (                                     [id] => 1                                     [category_name] =>                                     [type] => general                                     [date_added] => 2014-04-05                                 )                              [_related:cactiverecord:private] => array                                 (                                 )                              [_c:cactiverecord:private] =>                              [_pk:cactiverecord:private] => 1                             [_alias:cactiverecord:private] => t                             [_errors:cmodel:private] => array                                 (                                 )                              [_validators:cmodel:private] =>                              [_scenario:cmodel:private] => update                             [_e:ccomponent:private] =>                              [_m:ccomponent:private] =>                          )                      [member] => member object                         (                             [_new:cactiverecord:private] =>                              [_attributes:cactiverecord:private] => array                                 (                                     [id] => 1                                     [screen_name] => prashantb                                     [email] => prashantbharambe22@gmail.com                                     [date_added] => 2014-04-05                                     [first_name] => prashant                                     [last_name] => bharambe                                 )                              [_related:cactiverecord:private] => array                                 (                                     [profile] => memberprofile object                                         (                                             [_new:cactiverecord:private] =>                                              [_attributes:cactiverecord:private] => array                                                 (                                                     [id] => 1                                                     [member_id] => 1                                                     [city] => kalyan                                                     [state] => maharashtra                                                     [country] => india                                                     [designation] => php developer                                                     [date_added] => 2014-04-05                                                 )                                              [_related:cactiverecord:private] => array                                                 (                                                 )                                              [_c:cactiverecord:private] =>                                              [_pk:cactiverecord:private] => 1                                             [_alias:cactiverecord:private] => t                                             [_errors:cmodel:private] => array                                                 (                                                 )                                              [_validators:cmodel:private] =>                                              [_scenario:cmodel:private] => update                                             [_e:ccomponent:private] =>                                              [_m:ccomponent:private] =>                                          )                                  )                              [_c:cactiverecord:private] =>                              [_pk:cactiverecord:private] => 1                             [_alias:cactiverecord:private] => t                             [_errors:cmodel:private] => array                                 (                                 )                              [_validators:cmodel:private] =>                              [_scenario:cmodel:private] => update                             [_e:ccomponent:private] =>                              [_m:ccomponent:private] =>                          )                  )              [_c:cactiverecord:private] =>              [_pk:cactiverecord:private] => 1             [_alias:cactiverecord:private] => t             [_errors:cmodel:private] => array                 (                 )              [_validators:cmodel:private] =>              [_scenario:cmodel:private] => update             [_e:ccomponent:private] =>              [_m:ccomponent:private] =>          ) )    

but need result in following format.

 array (     [0] => array      (         [id] => 1,         [post_text] => sales needs increase end of month. don't wnat reason behind this,         [member_id] => 2,         [category_id] => 3,         [published] => 0,         [draft] => 1,         [date_added] => 2014-04-06,         [category] => array (             [id] => 1,             [category_name] => anything,             [type] => general,             [date_added] => 2014-04-05,         ),         [member] => array (             [id] => 1,             [screen_name] => prashantb,             [email] => prashantbharambe94@gmail.com,             [date_added] => 2014-04-05,             [first_name] => prashant,             [last_name] => bharambe,             [profile] => array(                 [id] => 1                 [member_id] => 1                 [city] => kalyan                 [state] => maharashtra                 [country] => india                 [designation] => php developer                 [date_added] => 2014-04-05             )         )     ) ) 

in short need attributes values in 1 array. ( model attributes , related model attributes )

i new yii. please me on this.

yii doesn't work arrays. each db record represented activerecord object. way can access column values this:

echo $model->post_text; // sales needs increase... echo $model->date_added; // 2014-04-06 echo $model->etc... 

if did set relations right, can access data this:

echo $model->category->category_name; // echo $model->member->screen_name; // prashantb 

you have create array showed manually. if still need data in array, can access attributes value:

print_r($model->attributes); // array( [id] => 1, [post_text] => 'sales needs increase', ...) 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -