我正在实现自己的 API。我在这里学习教程。即使我遵循它,我也很难让我的 API 正常工作。
我不明白 CodeIgniter REST Server 和 CodeIgniter REST Client 有什么区别。如果有人向我解释这将是一个很大的帮助。
现在我真正的问题是:我在下面有一个控制器,我扩展了教程中编写的 REST_Controller.php。
class Call extends REST_Controller
{
public function news()
{
// initialize you setting
$config = array(
'server' => 'localhost'
);
$this->rest->initialize($config);
// Set method of sending data
$method = 'post';
// create your param data
$param = array(
'id' => '1',
'name' => 'test'
);
// url where you want to send your param data.
$uri = 'http://192.90.123.908/api_v1/index.php';
// set format you sending data
$this->rest->format('application/json');
// send your param data to given url using this
$result = $this->rest->{$method}($uri, $params);
$data=array(
'id' => '1',
'name' => 'test'
);
print_r($data);
}
}
我期望的是当我访问这个 url 时http://localhost/website/index.php/call/news
。我将收到 JSON 响应。但我得到的是
{"status":false,"error":"Unknown method"}
。我找不到问题所在。