This repository was archived by the owner on Dec 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 281
Rest controller
Steven Lu edited this page Jul 30, 2014
·
3 revisions
CodeIgniter by default doesn't have a good way to interact a REST library, so we included one from philsturgen. There's a great article on how to use it.
<?php
require(APPPATH.'libraries/REST_Controller.php');
class Name extends REST_Controller {
function index_get() {
$variable = $this->get('variable');
$this->response(array('data' => $variable));
}
function index_post() {
$variable = $this->post('variable');
}
function index_delete() {
$variable = $this->delete('variable');
}
function index_put() {
$variable = $this->put('variable');
}
}
- Note the end of the function names, this defines the REST type.
- You call the controller index.php/Name/index, and the REST type will call the proper function
- You can set the default response type in
config/rest.phpbut you can also appendformat/jsonto the end of your URLs to get different data outputs. - When doing GET variables, you must define it within the URL itself such as
variable/variable_content. Make sure you URL encode these or it'll complain (for security reasons).