我已经在 Codeigniter - Rest Server 上遇到了一周的问题。我有一个名为Users的控制器,有 2 种方法all_users_get和register_post。
- all_users_get工作正常。
register_post
returns { "status": false, "error": "Unknown method" }
如果我改变方法all_users_get方法,我会得到同样的错误,只适用于 GET
<?php
use Restserver\Libraries\REST_Controller;
defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH . 'libraries/REST_Controller.php';
require APPPATH . 'libraries/Format.php';
class Users extends REST_Controller {
function __construct()
{
// Construct the parent class
parent::__construct();
$this->load->model('user_model');
// Configure limits on our controller methods
// Ensure you have created the 'limits' table and enabled 'limits' within application/config/rest.php
$this->methods['users_get']['limit'] = 500; // 500 requests per hour per user/key
$this->methods['users_post']['limit'] = 100; // 100 requests per hour per user/key
$this->methods['users_delete']['limit'] = 50; // 50 requests per hour per user/key
}
/**
* @method: GET
* Fetch all users
*/
public function all_users_get()
{
$users = $this->user_model->all_users();
// Check if the users data store contains users (in case the database result returns NULL)
if ($users)
{
// Set the response and exit
$this->response($users, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
}
else
{
// Set the response and exit
$this->response([
'status' => FALSE,
'message' => 'No users were found'
], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
}
$this->response($users, REST_Controller::HTTP_OK);
}
/**
* User Register
* *************************
*
* @param: fullname
* @param: email address
* @param: password
* @param: username
*
* *************************
* @method: POST
* @link : api/users/register
*/
public function resgister_post()
{
header('Access-Control-Allow-Origin: *');
$this->response("Teste", REST_Controller::HTTP_OK);
}
}
我正在使用 Xampp 在 localhost 中运行我的代码,我在phpinfo上找到了
_SERVER["REQUEST_METHOD"] 获取
我很困惑,我不知道这是否与 Xampp conf 或我的代码有关,请帮忙。谢谢你们