【问题标题】:Codeigniter server RESTCodeigniter 服务器 REST
【发布时间】:2015-06-22 14:59:31
【问题描述】:

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

我在文件 REST_Controller.php 中有一个错误

我的代码:

<?php

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

class Api extends REST_Controller {

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

}

我的 URI:ndd.com/api/test/format/json

我的回应:

<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"}

REST_Controller.php 中的第 41 行

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

我可以做些什么来修复错误?

【问题讨论】:

标签: php codeigniter rest


【解决方案1】:

Rest_controller.php 中试试这个代码

添加这些行

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

在开头

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


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

【讨论】:

  • 这并没有解决我的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-15
相关资源
最近更新 更多