A yii dataprovider that extends CActiveDataProvider in order to retrieve json. Attributes and relations that are fetched are recursively configurable. Furthermore key names can be replaced by aliases to compress the json size.
Feel free to contribute at GitHub.
Update on 06/11/2013 ¶
- Extracting the work horse that does the converting to new class ModelToArrayConverter. This class is usable stand-alone, too.
- New method getArrayCountData on JSonActiveDataProvider to retrieve just the count information, but no data.
- New callback onAfterModelToArray on JSonActiveDataProvider for optional custom extracting of data per model.
- For convenience relations can be defined now directly with an attributes description (instead of wrapping them into another array with a key "attributes")
- Examples at github readme updated
All changes do not break old behavior or usage!
Requirements ¶
Developed with Yii 1.10, but should work in older versions, too.
Convert Model With Relations To Php Array And Json
http://www.yiiframework.com/forum/index.php/topic/41922-convert-model-with-relations-to-php-array-and-json/
@farhad2161
Thank you for the note. your code is great for retrieving all information, but I needed a configurable approach to return just selected attributes and relations.
In an Api scenario it does make sense to keep control on which information is provided exactly and to reduce data overhead.
This post was helpful to me for what Sebastian is asking for
http://www.yiiframework.com/forum/index.php/topic/31994-howto-creating-more-complex-json-responses/pagep154131hlJSONArray#entry154131
Invalid argument supplied for foreach
Hi,
I think i've found a bug, i've submitted a pull request via github that fixes it ;)
https://github.com/sieppl/yii-json-dataprovider/pulls
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.