1

i have already set up a HMVC (i learned my setup from https://www.youtube.com/channel/UCkzjsv1ymTmdGpWTtZ7nM5A/videos ) and using it on my program. but i need it to re-code it into a RESTful type.

i have a MY_Controller.php file

<?php

class MY_Controller extends MX_Controller {

    function __construct()
    {
        parent::__construct();
        $this->load->module('Templates');
        $this->load->module('Login');

    }

}

?> 

this file is for loading modules easily. now i try to set up my REST_Controller etc. i have a folder like this

application
- - modules
- - - - Rest
- - - - - - controller
- - - - - - - Api.php
- - - - - - libraries
- - - - - - - Rest_Controller.php
- - - - - - - Format.php
- - - - - - config
- - - - - - - rest.php
- - - - - - models
- - - - - - views

i edited my REST_Controller.php from

abstract class REST_Controller extends CI_Controller {

into

abstract class REST_Controller extends MY_Controller {

and my Api.php is,

<?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');
    }
}

but when i do http://localhost/FOLDERNAME/Api/student_get on my browser

i got an error

404 Page Not Found

The page you requested was not found.

also i found this REST on mvc tutorial, it says that if i go to http://myapi.com/ it should open your codeigniter page, and it is good. but i only got

Buy this domain
The domain myapi.com may be for sale by its owner! etc.

i use Phil Sturgeon's REST Library by the way

im still not sure if what im doing is right. can someone please tell me what the error is or how i can do it correctly. thanks

kev_m
  • 325
  • 7
  • 30
  • Have you tried to place `Format` and `REST_Controller` into `APPPATH.'libraries'` directory and call those like that? – Tpojka Apr 20 '16 at 10:21
  • not yet. if ever i placed it like that, how can i check if its working – kev_m Apr 20 '16 at 10:26
  • still shows 404 page not found when i do `http://localhost/FOLDERNAME/Api/student_get` on my browser – kev_m Apr 20 '16 at 10:54
  • Try if `http://localhost/FOLDERNAME/index.php/Api/student_get` working. – Tpojka Apr 20 '16 at 10:57
  • still page not found @Tpojka – kev_m Apr 20 '16 at 11:28
  • If you exclude REST library, can you reach that page? – Tpojka Apr 20 '16 at 11:29
  • i have errors. my folder name and controller name are different. now that they are same i got this error `Unable to load the requested language file: language/english/rest_controller_lang.php` – kev_m Apr 20 '16 at 11:44
  • http://stackoverflow.com/questions/36742885/codeigniter-hmvc-rest-unable-to-load-the-requested-language-file-language-engli – kev_m Apr 20 '16 at 11:49
  • Put all `REST` files out of modules and place thse in coresponding locations in `APPPATH`. – Tpojka Apr 20 '16 at 12:16
  • i already did it. it has the same error – kev_m Apr 20 '16 at 12:20
  • I suggest to make over and follow video again. It is hard to say what is wrong if video series are functional and your code is not. – Tpojka Apr 20 '16 at 12:52
  • no. its not wrong. the problem is it is a setup for mvc(the video) and mine is for hmvc – kev_m Apr 22 '16 at 01:12

0 Answers0