我已经设置了一个HMVC(我从https://www.youtube.com/channel/UCkzjsv1ymTmdGpWTtZ7nM5A/videos学习了我的设置)并在我的程序中使用它。但我需要它将其重新编码为RESTful类型。
我有MY_Controller.php
个文件
<?php
class MY_Controller extends MX_Controller {
function __construct()
{
parent::__construct();
$this->load->module('Templates');
$this->load->module('Login');
}
}
?>
此文件用于轻松加载模块。现在我尝试设置我的REST_Controller等。我有一个像这样的文件夹
application
- - modules
- - - - Rest
- - - - - - controller
- - - - - - - Api.php
- - - - - - libraries
- - - - - - - Rest_Controller.php
- - - - - - - Format.php
- - - - - - config
- - - - - - - rest.php
- - - - - - models
- - - - - - views
我从
编辑了我的REST_Controller.php
abstract class REST_Controller extends CI_Controller {
到
abstract class REST_Controller extends MY_Controller {
我的Api.php
是,
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH.'modules/Rest/libraries/REST_Controller.php';
class Api extends REST_Controller {
function __construct() {
parent::__construct();
}
function student_get(){
$this->response('My first API response');
}
}
但是当我在浏览器上http://localhost/FOLDERNAME/Api/student_get
时
我收到了错误
404 Page Not Found
The page you requested was not found.
我也在mvc教程上找到了这个REST,它说如果我去http://myapi.com/它应该打开你的codeigniter页面,这很好。但我只有
Buy this domain
The domain myapi.com may be for sale by its owner! etc.
顺便使用Phil Sturgeon's REST Library
我仍然不确定我做的是否正确。有人可以告诉我错误是什么或我如何正确地做到这一点。感谢