php - CodeIgniter Rest Api
问题描述
I'm implementing the api in codeigniter using the restcontroller and format files shown in the gist below, once inserted I implement the Api.php file in the path specified below but when I try to call the api as a test I get the following error 404 not found, what is it and how can I fix this?
url to call api get: http://localhost/api/Api/testget
I have this file (rest controller and format) https://gist.github.com/riccardopirani/8878fcda16cae2ad45e4b1c9e624f619
Php Code(in folder /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);
}
}
解决方案
将方法名称写为test_get
. 保持类和文件名相同,然后调用 (get) http://localhost/[projectname]/index.php/api/book/test
推荐阅读
- c - 如何通知工作线程有一些工作要完成?
- java - 如何将 javafx 中 TextArea 的 isUndoable 属性设置为 true?
- python - Pygame 窗口打不开
- snowflake-cloud-data-platform - 雪花用户/角色管理
- github - 我应该在 Github 中为 PHP 使用什么 .gitignore?
- javascript - 通过 JavaScript 以编程方式禁用通知?
- java - 试图让我的重置按钮使计数器归零
- php - laravel attach() 函数在默认数据库中查找表
- python - 使用 discord.py-rewrite 进行全局检查功能
- pandas - Pandas DataFrame 有条件地合并