Php Codeigniter Rest库中不支持的协议
我正在尝试为现有数据库构建RESTAPI。有人建议我使用Chris Kacerguis提供的Rest API,但他的最新版本经常出现一些错误。然后,我决定使用以前的版本,该版本仍然有效,但存在“不受支持的协议”错误。我从他的基本GET示例复制粘贴了代码,但仍然存在相同的不受支持的协议错误Php Codeigniter Rest库中不支持的协议,php,rest,codeigniter,Php,Rest,Codeigniter,我正在尝试为现有数据库构建RESTAPI。有人建议我使用Chris Kacerguis提供的Rest API,但他的最新版本经常出现一些错误。然后,我决定使用以前的版本,该版本仍然有效,但存在“不受支持的协议”错误。我从他的基本GET示例复制粘贴了代码,但仍然存在相同的不受支持的协议错误 <?php defined('BASEPATH') OR exit('No direct script access allowed'); use chriskacerguis\RestServer\R
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
use chriskacerguis\RestServer\RestController;
class Api extends RestController {
function __construct()
{
// Construct the parent class
parent::__construct();
}
public function users_get()
{
// Users from a data store e.g. database
$users = [
['id' => 0, 'name' => 'John', 'email' => 'john@example.com'],
['id' => 1, 'name' => 'Jim', 'email' => 'jim@example.com'],
];
$id = $this->get( 'id' );
if ( $id === null )
{
// Check if the users data store contains users
if ( $users )
{
// Set the response and exit
$this->response( $users, 200 );
}
else
{
// Set the response and exit
$this->response( [
'status' => false,
'message' => 'No users were found'
], 404 );
}
}
else
{
if ( array_key_exists( $id, $users ) )
{
$this->response( $users[$id], 200 );
}
else
{
$this->response( [
'status' => false,
'message' => 'No such user found'
], 404 );
}
}
}
}
在REST配置文件中选中此选项
$config['force_https'] = TRUE;