Welcome Guest, Not a member yet? Register   Sign In
Problems with Codeigniter HMVC subfolders
#1

[eluser]Timothy_[/eluser]
Hello,

I have encountered an issue using subfolders with Codeigniter + HMVC.

Code:
/system/application/modules/welcome/controllers/staff/welcome.php
To access this I have to access it via http://www.app.com/welcome/staff/welcome

Unfortunately this doesn't fit the rest of my URL structure.

How can I remove the first welcome from the URL so the URL is http://www.app.com/staff/welcome

I have tried adding a route within the module:

Code:
/system/application/modules/welcome/config/routes.php
like:

Code:
$route['staff/welcome'] = "welcome/staff/welcome";
but unfortunately no luck.

Adding this route to the real codeigniter route file works but I feel that adding code external of the modules to get modules to work misses the point of adopting modularisation.

I hope someone is able to help.

Thanks,

Tim
#2

[eluser]wiredesignz[/eluser]
There is no staff module so you must use application level routing.
#3

[eluser]Timothy_[/eluser]
Thank-you wiredesignz for responding,

When you say "Application Level Routing" I assume you mean this will only work from the main CI routes file? Obviously this is not ideal when I am trying to implement "modules" that are meant to work independently from the main CI app.

It seems every time I try and implement HMVC I hit this same wall but perhaps I am the only one who is trying to get controller subfolders working as they do in CI, something I'm sure I read HMVC could do.
#4

[eluser]InsiteFX[/eluser]
You can create your own config and routes file in your modules.

module_name/config/config.php
module_name/config/routes.php

InsiteFX
#5

[eluser]Timothy_[/eluser]
Hi InsiteFX,

Yes this would be ideal!

I have tried adding a route within the module.

Code:
/system/application/modules/welcome/config/routes.php
like:

Code:
$route['staff/welcome'] = "welcome/staff/welcome";

but unfortunately no luck.

I am probably doing something wrong, but when I pasted the above route into the REAL routes file it worked so I'm not sure...

Thanks anyway,

Tim
#6

[eluser]InsiteFX[/eluser]
You can try something like this, but not tested. But you should get the idea...
Code:
$route['staff/welcome(:any)?'] = 'staff$1';

InsiteFX
#7

[eluser]InsiteFX[/eluser]
Sorry about the double post I got caught in the CI Maintence tonight!

You can try something like this, but not tested. But you should get the idea...
Code:
$route['staff/welcome(:any)?'] = 'staff$1';

InsiteFX
#8

[eluser]wiredesignz[/eluser]
@Timothy_, If the first URL segment == staff, how can you expect the routes file in the welcome module to get loaded?
#9

[eluser]Timothy_[/eluser]
@wiredesignz, I am not familiar with how HMVC is implemented.

For all I know the config files might be loaded at runtime, maybe the entire modules directory might be scanned for CI routes files, maybe it sends emails to NASA..? I had a look under the hood but it is out of my league.

So to summarise HMVC is ONLY triggered when a corresponding directory (ie welcome) is found in the modules directory?

Thanks for your patience.

Tim
#10

[eluser]Timothy_[/eluser]
[quote author="InsiteFX" date="1305108081"]You can try something like this, but not tested. But you should get the idea...
Code:
$route['staff/welcome(:any)?'] = 'staff$1';

InsiteFX[/quote]

Thanks for trying InsiteFX. I tried but it didn't work, probably because of what wiredesignz said. I tried adding a generic route to my main application routes file but it puts all my other (real) controllers into an infinite loop.

Code:
$route['staff/([a-z]+)'] = '$1/staff/$1';

Work perfectly for all my modules though Wink

I guess I can't have it both ways, was worth a try and thanks again for helping me out.

Tim




Theme © iAndrew 2016 - Forum software by © MyBB