1
votes

I use HMVC wiredesignz third party to use modular structure for Codeigniter.

I there a way to create a subfolder in the modules directory ?

I want something :

modules
    module1 
       controllers
           Module1.php
       ...
    admin
       module2
           controllers
               Module2.php
            ...    
       module3
           controllers
               Module3.php
            ...

Of course I've tried to call with :

base_url('admin/module2/index');

I've got a 404 error. Is this possible ?

1
I guess it's best to ask... why are you trying to access a sub Module via a url? - TimBrownlaw
Hum ? because you access controllers by URL in codeigniter. Module2 = controller's name, index = function's name in controller. - Vincent Decaux
Yep my question was a silly answer but what I was trying to get at it is, the default behavior is controller/method. I'll go and have a read up on it. - TimBrownlaw
Ok, I've just knocked up a little test site and it appears that out of the box, you cannot have modules inside modules, ie sub modules. But you can have sub folders under your controllers,models,views in your admin module for instance, if you needed the separation. The routes are handled in thirdparty/MX/Router.php so if you really needed to, that'd be the place to perform a hack. - TimBrownlaw
Yeah thanks, this is what I thought :( I will try a new method so - Vincent Decaux

1 Answers

0
votes

You can do it like this:

├── modules
    ├── module1 
    |   └── controllers
    |       └── Module1.php
    |     
    └── admin
        └── controllers
        |   └── Admin.php
        |   └── Submodule1.php
        |   └── Submodule2.php
        | 
        └── views
            └── subviews1

And the call them this way

# Calling the main module (admin)
base_url('admin');
base_url('admin/index');
base_url('admin/somefunction');

# Calling a sub module
base_url('admin/submodule1');
base_url('admin/submodule1/index');
base_url('admin/submodule1/somefunction');

# Loading a view of a submodule
$this->load->view('submodule1/myview');

To avoid name conflicts DO NOT use the name of a submodule as function name in mainmodule.