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( 'japi'=>'JApi', ); } }
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
pls upload the extendsion
@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.
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 login to leave your comment.