Welcome Guest, Not a member yet? Register   Sign In
Magic routing for modules
#1
Lightbulb 

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
Reply
#2

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.
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply
#3

(This post was last modified: 07-24-2019, 05:21 PM by InsiteFX. Edit Reason: spelling error new keyboard )

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

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/codeig...Routes.php
Reply
#5

(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!
Reply
#6

I used code modules cong/route. Php too
Dont need magic route
Enlightenment  Is  Freedom
Reply
#7

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.
Reply
#8

Auto routing is prone to security problems.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#9

(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?
Reply
#10

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




Theme © iAndrew 2016 - Forum software by © MyBB