CodeIgniter Forums
Magic routing for modules - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29)
+--- Thread: Magic routing for modules (/showthread.php?tid=74116)

Pages: 1 2


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 - suraj@codegniter - 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


RE: Magic routing for modules - UC_SUJITH - 07-02-2022

Auto route is a good thing when developing big applications. Big applications may contain 100s of URLs and adding each and everything to route is not a 'friendly' solution. And auto-routing from modules is already available with many other frameworks like Yii. If this can be added to the Codeigniter, then that would be great.


RE: Magic routing for modules - InsiteFX - 07-02-2022

Auto routing is prone to security problems.


RE: Magic routing for modules - kenjis - 07-03-2022

(07-02-2022, 07:05 AM)UC_SUJITH Wrote: auto-routing from modules is already available with many other frameworks like Yii.

What is auto-routing from modules?


RE: Magic routing for modules - kenjis - 04-16-2023

Module Routing for Auto Routing Improved will be introduced in v4.4.0.
https://github.com/codeigniter4/CodeIgniter4/pull/7416