1
votes

I am implementing HMVC in codeignter3. I have added all the required file in core and third_party folder.

I have also created modules folder. Inside module I have created frontend folder Inside frontend folder I have created One folder test inside that I have created 3 Folder controllers, models and view. In controllers folder I have created Test.php and in models model created with name Test_model.php and in views one file created index.php

My controller code is

<?php
class Test extends MX_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->model('test_model');
    }

public  function index()
    {

        $data['main_content'] = 'home/index';
        $this->load->view('front/layout', $data);
    }

}
?>

inside application/config/routes.php

$route['test'] = "frontend/test/Test/index"; 

When I am accessing it through localhost/myprojectfoldername/test I am getting 404

3

3 Answers

1
votes

yes, this gives you an error. because you have created modules folder inside the module folder.

you have to create modules folder in your application folder not to the inside of another folder the path is defined in mx_loader application>modules so the code is not fined the class.

change its directory and refresh it so the error will remove.

further help uses these links:

http://www.dcaulfield.com/how-to-install-codeigniter-hmvc/

Or you can directly download from my gmail drive :

https://drive.google.com/open?id=1Viyo7CQcjJNkBv5ahyiOs5RwwXiOVopg

afer downlad and set up, hit url:

http://localhost/hmvc/home

0
votes

Use like this:

 $route['some-route'] = "yourcontroller/yourmethod";

or in other words:

$route['user'] = 'user/login';
0
votes

One thing about HMVC Pattern in Codeigniter is, you need to follow the folder structure very well.

In your description you said you have created a Test.php file in your controller which resides in a folder called "frontend" which is in another folder "test" in your modules folder too.

Now the trick here is, If your controller name (Test.php) is equal to the folder name (test), you can simply call it like this:

$route['test'] = "frontend/test/index"; 

Instead of this:

$route['test'] = "frontend/test/Test/index"; 

On the other side let's say you have created another file( or controller) in the text folder called User.php then you can set your route as:

$route['test/user'] = "frontend/test/user/index"; 

Then again in your route code example I noticed you tried to use the Uppercase for the "Test", it does not really matter you can just use a lowercase "test" instead: $route['test'] = "frontend/test/test/index"; But note this was just to explain whether it is case-sensitive or not.

Try your hands and it and let's see the outcome