Codeigniter REST Server

I am creating a server based on codeigniter rest v 2.1.1 following this tutorial. http://code.tutsplus.com/tutorials/working-with-restful-services-in-codeigniter-2--net-8814

I have an error in my REST_Controller.php file

My code:

<?php

require(APPPATH . 'libraries/REST_Controller.php');

class Api extends REST_Controller {

    function test_get() {
    $this->response(array('success' => 'Yes it is working'), 200);
    }

}

      

My URI: ndd.com/api/test/format/json

My answer:

<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  Creating default object from empty value</p>
<p>Filename: libraries/REST_Controller.php</p>
<p>Line Number: 41</p>

</div>{"success":"Yes it is working"}

      

Line 41 in REST_Controller.php

// How is this request being made? POST, DELETE, GET, PUT?
        $this->request->method = $this->_detect_method();

      

What can I do to fix the error?

+3


source to share


1 answer


Try this code at Rest_controller.php

Add this line

if(!is_object($this->request))
         {
            $this->request= new stdClass();
         }

      



at the beginning

publict function __construct()
{
   parent::__construct();

   $this->load->config('rest');

  //some where here like 

   if(!is_object($this->request))
         {
            $this->request= new stdClass();
         }

$this->request->method = $this->_detect_method();


......
....
...
}

      

+6


source







All Articles