ben dog Thu Jan 26 03:44:27 -0500 2012

Subject: Any progress on an easier json encoding?


Just trying out php.activerecord and first impressions are great.

One of my test required to send some records back as json... seem really difficult to send a collection of records as json.. I found previous forum posts asking the same question a while back but nothing recently.

Is there any way to send a bunch of records as json?


Mr. Carl Thu Jan 26 15:21:58 -0500 2012

Short answer I don't know because I'm also new however I did find something that may help you.


Code snippet from the url:

1 $models=Bla::model()->findAll();
2 $data=array_map
3 (
4        create_function('$m','return $m->getAttributes(array(\'id\',\'name\'));'),$models
5 );
6 echo json_encode($data);

Yoan B Sat Jan 28 10:25:05 -0500 2012

@MrCarl it's PHP 5.3, you shouldn't need create_function anymore.