How can I fix this error in Codeigniter HMVC

2

Someone could help me with this error in Codeigniter 3.0.6 with the HMVC, apparently it does not detect the driver inside the module. These are my code lines.

config.php

$config['base_url'] = 'http://web.com/project/';
$config['index_page'] = 'index.php';
$config['uri_protocol'] = 'REQUEST_URI';

routes.php

$route['default_controller'] = 'login/home';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

.htaccess

RewriteEngine on

RewriteCond $1 !^(index\.php|assets|images|files|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

Tree of my project

project
| application
| | config
| | | config.php
| | | routes.php
| | modules
| | | login
| | | | models
| | | | | ...
| | | | views
| | | | | ...
| | | | controllers
| | | | | home.php
|.htaccess

My error result:

  

404 Page Not Found

     

The page you requested was not found.

    
asked by Jean Paul 22.06.2016 в 00:03
source

3 answers

1

You should never alter the order of the folders that come by default in CodeIgniter.

A module folder appears in your tree that does not come by default. The structure should be:

project
| application
| | config
| | | config.php
| | | routes.php
| | models
| | | ...
| | views
| | | ...
| | controllers
| | | home.php
|.htaccess

So that controllers, models and views are in the application folder. In this way, your default driver can be set

$route['default_controller'] = 'home';

As Alfonso Carrasco indicates, since the path specified in the default_controller parameter must be relative to the application / controllers directory of your project.

However, directories can be created to structure the code in an organized manner. For example, you can create directories in the views folder to be able to distinguish views of different sections of the website. The reference to a view in a folder could be:

$this->load->view('user/profile');

This would load the "profile" view hosted in the views / user folder.

    
answered by 24.07.2016 в 05:07
0

In your tree you indicate that the controller is directly root, but in your default_controller you are indicating that you have it in a folder called: /login .

Your tree:

project
| application
| | config
| | | ..
| | modules
| | | login
| | | | models
| | | | | ...
| | | | views
| | | | | ...
| | | | controllers
| | | | | home.php <- Aquí indicas que la carpeta; login no existe.

You must change the following:

$route['default_controller'] = 'home';

and voila, it should work.

    
answered by 22.06.2016 в 00:14
0

To create modules or versions in CodeIgniter and that your code works, you must create the folders within Controller and not modify the original order.

Example:

You have it like this:

project 
| config
| | | ..
| | modules
| | | login
| | | | models
| | | | | ...
| | | | views
| | | | | ...
| | | | controllers
| | | | | home.php

It should be like this:

project
| application
| | config
| | | config.php
| | | routes.php
| | models
| | | ...
| | views
| | | ...
| | **controllers** 
| | | login
| | | | home.php
|.htaccess
    
answered by 21.03.2017 в 16:28