[英]Codeigniter server REST
我按照本教程在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();
我該怎么做才能解決錯誤?
在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();
......
....
...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.