Yii 1.1: japi

JApi, short for JSON API, is an action handler for Yii.

JApi maps requests in the form ?r=controller/japu&action=method to controller->japiMethod. Then, anything returned from japiMethod is encoded in JSON and sent to the client. Parameters in the function are mapped to _GET varibles. JApi follows the requirments of the parameters, such as optional and required.


I am have used it on Yii 1.1.7 and 1.1.10, may work on others as well


Download and place JApi.php into APPROOT/protected/components

Then in ExampleController.php

class ExampleController extends Controller
    public function japiTest($required,$optional="abc")
        return array('r'=>$required,'o'=>$optional);
    public function actions()
        return array(

Request: /?r=example/japi&action=test&required=text
Returns: {'r':'text','o':'abc'}

Request: /?r=example/japi&action=test&required=text&optional=text2
Returns: {'r':'text','o':'text2'}

Request: /?r=example/japi&action=test
Returns: 400 Malformed Request

You can mix standard actions and JApi actions into one controller


Total 3 comments

#9594 report it
bitshine at 2012/08/27 04:49am
no downloads yet

pls upload the extendsion

#8166 report it
mrkmg at 2012/05/14 10:00am
Simple Update

@Raoul, Updated based on your recommendation

Also fixed HTTP error codes to be more informative and correct

Also added a fallback for no action being passed, now acts like normal actions and defaults to index.

#8155 report it
Raoul at 2012/05/13 06:41am

Thanks for this extension ! ... my first tests are positive. Just one remark to make it even more generic : in JApi.php, replace '<?' by '<?php'

Leave a comment

Please to leave your comment.

Create extension
No downloadable files yet