1

我已经设置了一个 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顺便用

我仍然不确定我所做的是否正确。有人可以告诉我错误是什么或我如何正确地做到这一点。谢谢

4

0 回答 0