简体   繁体   中英

testing API extends REST_Controller codeIgniter

Hi I want to create a Restful API in codeIgniter. So I started with testing chris kacer code ( https://github.com/chriskacerguis/codeigniter-restserver ), but when i tape

localhost:9090/CodeIgniter/index.php/example/user/id/1

I always get this response:

{"status":false,"error":"Unknown method."}

I don't know where is the problem. i configured my routes.php

($route['default_controller'] = "example";)

and config.php

($config['base_url'] = 'http://localhost:9090/CodeIgniter/';)

and it still not working. Can anyone help me please and thank you.

When working with rest_codeighniter api the controller logic is kinda different in the sense that ur "methods/public functions" in the ur controller class(the one that extends the rest_controller) are created by combining the RESOURCE name and the HTTP method(eg get,post,put etc). therefore if ur resource name is "user" and u want to make a "get" http call, ur method/function would be declared as "public function user_get(){ //ur code here } " .

Looks like you haven't included the REST library class file. If that's the case then adding the lines below should resolve your error,

// including rest api class
require APPPATH . '/libraries/REST_Controller.php';

// use namespace
use Restserver\Libraries\REST_Controller;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM