Я создаю api для отдыха с использованием фреймворка codeigniter. Я скачал код по следующей ссылке: https://github.com/halimus/codeigniter-rest-api
Теперь в почтальоне, если я поставлю следующий URL-адрес с помощью метода GET или POST, тогда будет запущен api: «http: // локальный / codeigniter-rest-api-master / api / пользователи». Но если я добавлю новую функцию «тестирование» и нажму следующий URL, тогда отображается ошибка "Страница 404 не найдена" «http: // локальный / codeigniter-rest-api-master / api / тестирование»
Вот мой код «Application / controller / api / users.php»:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH.'/libraries/REST_Controller.php';
class Users extends REST_Controller {
function __construct() {
parent::__construct();
$this->load->helper('api');
}
public function testing()
{
echo "hello world";
}
public function users_get(){
$this->load->model('Model_users');
$user_id = $this->get('id');
if ($user_id === NULL){
$users = $this->Model_users->get_many_by(array('status' => array('active', 'inactive')));
if ($users! = ""){
// Set the response and exit
$this->response($users, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
}
else{
// Set the response and exit
$this->response(array('status'=> false, 'message'=> 'The Specified user could not be found'), REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
}
}
// Find and return a single record for a particular user.
$user_id = (int) $user_id;
if ($user_id <= 0){
// Invalid id, set the response and exit.
$this->response(NULL, REST_Controller::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code
}
$user = $this->Model_users->get_by(array('user_id' => $user_id, 'status' => array('active', 'inactive')));
if (isset($user['user_id'])){
$this->response(array('status'=> 'success', 'message'=> $user));
}
else{
$this->response(array('status'=> 'failure', 'message'=> 'The Specified user could not be found'), REST_Controller::HTTP_NOT_FOUND);
}
}
}






Вам нужно будет переименовать вашу функцию в {ресурс} _ {HTTP_verb}.
В вашем случае testing_get.
Гдетестирование - это ресурс, а получить - это HTTP-команда.
При доступе к API с использованием URI: http: // локальный / codeigniter-rest-api-master / api / пользователи / тестирование / в методе ПОЛУЧИТЬ. test_get будет вызываться.
Подробно вы можете прочитать здесь: https://code.tutsplus.com/tutorials/working-with-restful-services-in-codeigniter--net-8814