Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter Rest库中不支持的协议_Php_Rest_Codeigniter - Fatal编程技术网

Php Codeigniter Rest库中不支持的协议

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

我正在尝试为现有数据库构建RESTAPI。有人建议我使用Chris Kacerguis提供的Rest API,但他的最新版本经常出现一些错误。然后,我决定使用以前的版本,该版本仍然有效,但存在“不受支持的协议”错误。我从他的基本GET示例复制粘贴了代码,但仍然存在相同的不受支持的协议错误

<?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;