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.
Requirements ¶
I am have used it on Yii 1.1.7 and 1.1.10, may work on others as well
Usage ¶
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
good
Thanks for this extension ! ... my first tests are positive. Just one remark to make it even more generic : in JApi.php, replace '<?' by '<?php'
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.
no downloads yet
pls upload the extendsion
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.