CodeIgniter Forums
Magic routing for modules - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forum-29.html)
+--- Thread: Magic routing for modules (/thread-74116.html)



Magic routing for modules - Fred9176 - 07-24-2019

Hi,

Would it be possible to enable magic routing for modules ?
This will be much easier than defining all routes manually

The URL should be /acme/blog/list, fo example, where acme is the name of the module, blog the controller and list the method .

This feature is already available,for instance, in the HMVC extension (MX) of CodeIgniter 3.

Thanks in advance.

Fred


RE: Magic routing for modules - albertleao - 07-24-2019

Not sure how to do this with HMVC (never used it) but I will recommend defining your routes. It may seem "easier" to start, but it does not scale well at all. Your routes.php file ends up becoming a very good blueprint for any devs that might join the project later on.

If this is a pet/small project, it may not matter though.


RE: Magic routing for modules - InsiteFX - 07-24-2019

I define all my routes in the module config folder route.php

I use a Group Closure to add them in makes it easier to do.


RE: Magic routing for modules - MGatner - 07-25-2019

Agree with @InsiteFX - you may define the routes yourself within the module using config/Routes.php. It isn't "magic" routing for the developer (though you can create them in bulk with wildcards or resource routes) but for the user including the module they shouldn't need to do anything.
Here's an example from one of my modules that, when installed, will instantly make https://example.com/workflows (among others) available on the site:
https://github.com/tattersoftware/codeigniter4-workflows/blob/develop/src/Config/Routes.php


RE: Magic routing for modules - [email protected] - 04-29-2021

(07-24-2019, 05:19 PM)InsiteFX Wrote: I define all my routes in the module config folder route.php

I use a Group Closure to add them in makes it easier to do.

Hi @InsiteFX,

Do you mean you were able to load the routes from the active module?

Actually, I want to load the routes from the active module.

I tried by looking into the HMVC MX_Router.php it seems the system is getting the active module name after the routes are initialized.

Can you please help me with this?

Thanks!


RE: Magic routing for modules - paliz - 06-09-2021

I used code modules cong/route. Php too
Dont need magic route