简体   繁体   中英

Problems with creating subfolders in CodeIgniter 3 HMVC

I have a project that contains several subfolders, such as:

  1. client/auth/login = model/view/controller
  2. client/auth/signup = model/view/controller
  3. admin/signin = model/view/controller

I set up my routes like this:

$route['default_controller'] = "admin/signin/signin";
$route['admin/sigin'] = "admin/sigin/signin/index";
$route['admin/(:any)'] = "admin/sigin/signin/";
$route['client/auth'] = "auth/login/login";

These routes are not working, which shows CodeIgniter 404 error page.

$route['default_controller'] = "admin/signin/signin";
$route['admin/signin'] = "admin/signin/signin/index";
$route['admin/(:any)'] = "admin/signin/signin/$1";
$route['client/auth'] = "auth/login/login";

Fixed typo's above. And I think your file structure is not correct. I use CI2, not sure how modules work in CI3. But the modules 'forgot_password' and 'signin' would be using the same models right? Why having them in separate folders/modules? This way when you make a change to the User model, you'll have to make the change in every User model in all modules (unless you don't need it in that cases, but still I wouldn't risk building my app like that)

- modules
    - Admin
        - controllers
            - user.php // Will have methods like signin(), add(), view(),...
    - Client
        - controllers
            - auth.php // Will have methods like signin(), signout(), ...
        - models // This will hold models you don't need in Admin module
                 // other models should be in the default models folder, so each module will be able to access them.

The routes would look like this:

$route['default_controller'] = "admin/user/signin"; // admin module, user controller, signin method
$route['admin/signin'] = "admin/user/signin";
$route['admin/(:any)'] = "admin/content/$1"; // admin module, content controller, (:any) method (content being an example, I have it in my CMS project)
$route['client/auth'] = "client/auth/login"; // client module, auth controller, login method

I solved it..In config file, I have added the following line of code;

$config['modules_locations'] = array(
    APPPATH.'modules/'                   => '../modules/',
    APPPATH.'modules/admin/' => '../modules/admin/', 
    APPPATH.'modules/client/' => '../modules/client/', 
);

It works like a charm..:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM