Welcome Guest, Not a member yet? Register   Sign In
Modular Separation and default controller
#1

[eluser]mseo[/eluser]
Hi there!

I'm trying to us a a default controller with Modular Separation.

I placed my routes.php in
Code:
application - modules - my_module - config - routes.php
where I defined
Code:
$route['default_controller'] = "my_controller";

But I always get an 404 when I call
Code:
http://.../.../my_module/


Code:
http://.../.../my_module/my_controller

works without any problems.

Any ideas what could be wrong? Does the default controller work with your Modular Separation?

mseo
#2

[eluser]loosetops[/eluser]
You can't do default_controller with modular separation, the trick is to do a normal route

Do it like below in your modules routes.php
Code:
//$route['default_controller'] = 'my_controller'; // wrong
$route['module_name'] = 'my_controller'; // right
#3

[eluser]mseo[/eluser]
Okay, thank you. I'll try it this way!

But the description on http://codeigniter.com/wiki/Modular_Separation/ says the following:

Code:
- Each module may contain a config/routes.php file where routing and a default controller can be defined for that module.
#4

[eluser]loosetops[/eluser]
It says that but you have to define the default controller with a module name.

I wanted to hack my MS so I could $route['default_controller'], then I realized it would have made it messy. Since all the routes are loaded at the same time you would have to resolve the 'default_controller' key in every routes file(except the top one) to avoid collision.

This would make MS less efficient yet we could have just used the module_name to begin with. I'm guessing the MS creator thought about it. That line in the wiki should be expounded upon to mention using the module_name as the key.
#5

[eluser]mseo[/eluser]
It works! Thank you for the great explanation.
#6

[eluser]Phil Sturgeon[/eluser]
[quote author="loosetops" date="1281575118"]It says that but you have to define the default controller with a module name.

I wanted to hack my MS so I could $route['default_controller'], then I realized it would have made it messy. Since all the routes are loaded at the same time you would have to resolve the 'default_controller' key in every routes file(except the top one) to avoid collision.

This would make MS less efficient yet we could have just used the module_name to begin with. I'm guessing the MS creator thought about it. That line in the wiki should be expounded upon to mention using the module_name as the key.[/quote]

You are part right and part wrong.

The initial routes library is parsed then the module library is parsed. MS will not parse EVERY routes file as there is no point. This is something that Matchbox does and it doesn't work very well.

MS does allow you to create a default controller for your module, but not using default_controller. You can use:

Code:
route['module_name'] = 'my_controller'; // right

like you suggested.




Theme © iAndrew 2016 - Forum software by © MyBB