【问题标题】:CodeIgniter Rest ApiCodeIgniter 休息 API
【发布时间】:2021-06-04 11:28:00
【问题描述】:

我正在使用下面要点中显示的restcontroller和格式文件在codeigniter中实现api,一旦插入,我就会在下面指定的路径中实现Api.php文件但是当我尝试调用api作为测试时我得到未找到以下错误 404,它是什么以及如何解决?

调用api get的url: http://localhost/api/Api/testget

我有这个文件(休息控制器和格式) https://gist.github.com/riccardopirani/8878fcda16cae2ad45e4b1c9e624f619

PHP代码(在文件夹/controllers/api/Api.php:

<?php

use Restserver\Libraries\REST_Controller;

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

      
    class Books extends REST_Controller {
      
        function testget()
        {
           $data = array("message"=>"RESTfull API sample");
           $this->response($data);
        }
            
    }

【问题讨论】:

  • 我想你应该使用helpers 来处理这种事情。
  • 链接无法访问
  • 它对我有用,但在这种情况下,您可以搜索“codeigniter 3 helpers”。
  • 我试图寻找您提出的解决方案之一,但经过多次尝试我没有解决错误

标签: php codeigniter codeigniter-3


【解决方案1】:

将方法名称写为test_get。保持类和文件名相同,然后调用(get)http://localhost/[projectname]/index.php/api/book/test

【讨论】:

    猜你喜欢
    • 2014-11-09
    • 2014-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多