Codeigniter RESTful API Server - XML ​​error?

I have read the following topics / tutorials:

And I still can't figure out why I am related to route problems and XML problems. My web service controller is in the foldercontrollers/api/webservice.php

<?php defined('BASEPATH') OR exit('No direct script access allowed');

require APPPATH.'/libraries/RESTful/REST_Controller.php';

class webservice extends REST_Controller{

     function get() {
        $data = array();
        $data['name'] = "TESTNAME";
        $this->response($data); 
     }
}

      

There is no need to add routes in the tutorials , and in order to get the XML page error, I needed to add the following route, otherwise it won't work:

$route['api/webservice/get'] = 'api/webservice/get';

      

My codeIgniter structure folder:

 > application
   > config
       rest.php (did not change anything from the GitHub download)
   > controllers
      > api
         webservice.php
         key.php
   > libraries
      > RESTful
         REST_Controller.php (changed line 206 to: $this->load->library('RESTful/format');)
         format.php

      

From the tutorial, the following link works without routes:

http://localhost/testRestful/index.php/api/example/users

      

Mine only works with route

http://localhost/myproject/index.php/api/webservice/get

      

And I get the following error: enter image description here He doesn't say anything. I can't figure out which file is talking about the error.

+3


source to share


1 answer


you cannot write get function if using REST_Controller. provide a name for the function test_get

.

class webservice extends REST_Controller{
 function test_get() {
    $data = array();
    $data['name'] = "TESTNAME";
    $this->response($data); 
 }
}

      

You can now navigate to the page using this link



http://localhost/myproject/index.php/api/webservice/test

      

_get and _post are appended to the end of the function to detect either a receive request or after a request.

+1


source







All Articles