ivantcholakov / starter-public-edition-4

A PHP application starter, based on CodeIgniter 3
MIT License
165 stars 89 forks source link

routes per module ? #31

Closed quasiperfect closed 8 years ago

quasiperfect commented 10 years ago

hi

how would you go for adding routes / module ?

in my situation every module can have multiple controllers and not always the controller name can be the route

thanks in advance for your response

ivantcholakov commented 10 years ago

Could you give me some details, an example?

quasiperfect commented 10 years ago

sure sorry about that

i want to be able to have a config/routes.php inside the module and be read by the framework

so i can copy one folder that contains the module and that would make the module work the final target is to have every module like a self contained app

ivantcholakov commented 10 years ago

I think, you can place route.php within module configuration. Try it, it should work.

ivantcholakov commented 10 years ago

Sorry, routes.php

applications/_applicationname/modules/_modulename/config/routes.php

quasiperfect commented 10 years ago

i tried it doesn't work

ivantcholakov commented 10 years ago

I tried too, it does not work. I'll have a look.

ivantcholakov commented 10 years ago

See this commit: https://github.com/ivantcholakov/starter-public-edition-4/commit/2bffee7ad61b8afcfa320cd68edd13bd07bbca2d

This is an original link: http://iridadesign.com/starter-public-edition-4/www/playground/captcha This is the new link: http://iridadesign.com/starter-public-edition-4/www/playground/kcaptcha

ivantcholakov commented 10 years ago

In this regard I stick to the original HMVC implementation - https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/

The feature you asked about is undocumented.

Editi: Sorry, it is documented:

"Each module may contain a config/routes.php file where routing and a default controller can be defined for that module using:

<?php
$route['module_name'] = 'controller_name';

Controllers may be loaded from application/controllers sub-directories. Controllers may also be loaded from module/controllers sub-directories."

I found some information here: http://stackoverflow.com/questions/15640481/codeigniter-with-wiredesignz-hmvc-routing

It looks weird how it works, but maybe there is a reason.

Edit: He omits the module name in the value at the right side, the module name is already known.

ivantcholakov commented 10 years ago

PyroCMS uses this feature, here is an example: https://github.com/pyrocms/pyrocms/blob/2.2/develop/system/cms/modules/blog/config/routes.php

As I can see, they stick to the original logic too, only they have added supporting slugs from the database.

quasiperfect commented 10 years ago

thanks so much for your time

i tried and failed

for example lets say we have site (main app) manager (admin) users (module) login_controller i want to call this like so http://domain/manager/login logout_controller i want to call this like so http://domain/manager/logout users_controller i want to call this like so http://domain/manager/users etc would this work ? if so how can i define the routes ?

ivantcholakov commented 10 years ago

I don't understand your case.

site (main app) - this is the front-end application? http://domain ? manager (admin) - this is an application too? http://domain/manager ?

users (module) - in which application is this module?

  1. login_controller i want to call this like so http://domain/manager/login
  2. logout_controller i want to call this like so http://domain/manager/logout
  3. users_controller i want to call this like so http://domain/manager/users

In which application and in which module/modules are these controllers?

I can tell for sure that with module-level route configutation you can not do this:

http://domain/manager/users/login -> http://domain/manager/login

The segment users should be present in the result link, it is how it works.

Otherwise all the routes in all the modules should have been parsed, which is ineffective.

Use local routes.php if you redefine links that as results are inside the same module. Otherwise use the global routes.php.

I suspect, what you want to do is impossible.

ivantcholakov commented 10 years ago

This is sample of mnie, I don't use module-level routing definitions so far. my_module_structure

My preference in not making the modules quite big.

Just create separate modules login and logout and you will be fine.

quasiperfect commented 10 years ago

thanks for you input

"I suspect, what you want to do is impossible." i think you are right i will try to organize my modules some other way

ivantcholakov commented 9 years ago

TODO: To be examined in the future: https://github.com/Bigwebmaster/codeigniter-modular-extensions-hmvc

ivantcholakov commented 9 years ago

I must reopen this issue for not forgetting the research work that is to be done.

ivantcholakov commented 8 years ago

The idea in https://github.com/Bigwebmaster/codeigniter-modular-extensions-hmvc sounds complex for adaptation in this starter and I am not sure that I like it. Closing.