Search code examples
.htaccesscodeigniterroutescontrollershmvc

Autoload shared controllers in a HMVC codeigniter app


This is my path:

/api
    calltek
        application
            config
            controllers
            ...etc
        index.php
        .htaccess
    empresite
        application
            config
            controllers
            ...etc
        index.php
        .htaccess
    gestios
        config
        controllers
            Gestios_login.php
            Gestios_profile.php
        libraries
        models
    shared
        config
        helpers
        language
        libraries

Gestios and Shared are Packages. Calltek and Gestios are apps.

Calltek autoload.php loads resources from gestios and shared:

$autoload['packages'] = array(APPPATH.'../../gestios',APPPATH.'../../shared');

And in my routes.php i define paths calling a Gestios Controllers:

$route['auth'] = 'gestios_login/index';
$route['avatar'] = 'gestios_profile/avatar';
$route['profile/me'] = 'gestios_profile/me';
$route['profile/avatar'] = 'gestios_profile/avatar';
$route['profile/avatar/(:num)'] = 'gestios_profile/avatar/$1';
$route['profile/config'] = 'gestios_profile/config';

When i try to navigate to example.com/api/calltek/auth app send me a 404.

My calltek .htaccess it's fine:

RewriteEngine on

RewriteCond $1 !^(index\.php|media)
RewriteRule ^(.*)$ index.php/$1 [L]

Solution

  • Case Codeigniter dont autload de controller's as package (LINK) i found and alternative solution:

    Simply create a second controller and extend the shared controller:

    <?php defined('BASEPATH') OR exit('No direct script access allowed');
    
    require APPPATH.'/../../gestios/controllers/Gestios_login.php';
    
    class Auth extends Gestios_login {
        public function __construct(){
            parent::__construct();
        }
    }