简体   繁体   English

Codeigniter服务器REST

[英]Codeigniter server REST

I create a server on codeigniter rest v 2.1.1 by following this tutorial. 我按照本教程在codeigniter rest v 2.1.1上创建了一个服务器。 http://code.tutsplus.com/tutorials/working-with-restful-services-in-codeigniter-2--net-8814 http://code.tutsplus.com/tutorials/working-with-restful-services-in-codeigniter-2--net-8814

I have an error in the file REST_Controller.php 我在REST_Controller.php文件中有一个错误

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 我的URI:ndd.com/api/test/format/json

My response : 我的回复 :

<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 REST_Controller.php中的第41行

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

What can I do to fix the error? 我该怎么做才能解决错误?

Try this code in Rest_controller.php Rest_controller.php中尝试此代码

Add these line 添加这些行

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

in the starting of 在开始

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();


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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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