A data provider that extends CActiveDataProvider in order to retrieve an (configurable) json result

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

  1. Extracting the work horse that does the converting to new class ModelToArrayConverter. This class is usable stand-alone, too.
  2. New method getArrayCountData on JSonActiveDataProvider to retrieve just the count information, but no data.
  3. New callback onAfterModelToArray on JSonActiveDataProvider for optional custom extracting of data per model.
  4. For convenience relations can be defined now directly with an attributes description (instead of wrapping them into another array with a key "attributes")
  5. Examples at github readme updated

All changes do not break old behavior or usage!


Developed with Yii 1.10, but should work in older versions, too.


See Readme on GitHub


Total 4 comments

#15896 report it
chux at 2013/12/27 06:06pm
Invalid argument supplied for foreach


I think i've found a bug, i've submitted a pull request via github that fixes it ;)


#13493 report it
Sebastian K. at 2013/05/31 06:17pm

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.

Leave a comment

Please to leave your comment.

Create extension
No downloadable files yet