-1
defined('BASEPATH') OR exit('No direct script access allowed');

require('application/libraries/REST_Controller.php');

use Restserver\Libraries\REST_Controller;

class demo extends REST_Controller {

  function __construct(){

    parent::__construct();
  }

  public function demo1_get()
  {
    echo 'demo 1';
  }

} 

错误 图像在此处输入图像描述

这是我的 REST_Controller 在此处输入图像描述

嗨,我在制作 Codeigniter RESTful API 时遇到错误。请帮我解决这个问题。

4

2 回答 2

0

您需要点击链接https://itsolutionstuff.com/post/codeigniter-3-restful-api-tutorialexample.html

然后在你运行代码后你会得到一个小错误 Unable to load the requested language file: language/english/rest_controller_lang.php

问题是 codeigniter 找不到 rest_controller 翻译。你只需要创建这个文件 /application/languages/english/rest_controller_lang.php

然后复制并粘贴这段代码:

<?php
/*
 * English language
 */
$lang['text_rest_invalid_api_key'] = 'Invalid API key %s'; // %s is the REST API key
$lang['text_rest_invalid_credentials'] = 'Invalid credentials';
$lang['text_rest_ip_denied'] = 'IP denied';
$lang['text_rest_ip_unauthorized'] = 'IP unauthorized';
$lang['text_rest_unauthorized'] = 'Unauthorized';
$lang['text_rest_ajax_only'] = 'Only AJAX requests are allowed';
$lang['text_rest_api_key_unauthorized'] = 'This API key does not have access to the requested controller';
$lang['text_rest_api_key_permissions'] = 'This API key does not have enough permissions';
$lang['text_rest_api_key_time_limit'] = 'This API key has reached the time limit for this method';
$lang['text_rest_ip_address_time_limit'] = 'This IP Address has reached the time limit for this method';
$lang['text_rest_unknown_method'] = 'Unknown method';
$lang['text_rest_unsupported'] = 'Unsupported protocol';

希望这可以帮助

于 2019-09-09T12:38:02.373 回答
0

它应该是这样的:

确保您REST_Controller.php的库文件夹中有

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

require_once APPPATH . '/libraries/REST_Controller.php';


class Demo  extends REST_Controller
{
    function __construct(){

      parent::__construct();
    }

   public function demo1_get()
   {
     echo 'demo 1';
   }
}
于 2018-06-07T09:44:38.130 回答