2014年11月24日 星期一

CodeIgniter api route

http://localhost:81/index.php/api/user/index/1
http://localhost:81/index.php/api/user/1
http://localhost:81/index.php/api/user

Route::any('api/(:any)/(:any)/(:num)', '$1/api/$2/$3');
Route::any('api/(:any)/(:num)', '$1/api/index/$2');
Route::any('api/(:any)/(:any)', '$1/api/$2');
Route::any('api/(:any)', '$1/api');

public function index($id = FALSE)
{  
    $return_data = array('user_id' => $id, 'status' => 'success', message' => '');
                                                                                                                                   
    echo json_encode($return_data);
}




References :
Parsing URI segments and assigning them to variables - Bonfire Forums
Docs - My Bonfire

沒有留言:

張貼留言