CodeIgniter Forums
How to pull routes in spark command - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: How to pull routes in spark command (/showthread.php?tid=87232)



How to pull routes in spark command - ciUser43 - 03-28-2023

Previously up to version 4.2.12 I can call
PHP Code:
route_to('route_name'
and get the routes that I configured in the
PHP Code:
\app\Config\Routes.php 
, but since I upgraded to version 4.3.2 it seems that this is no longer possible due to the spark command not even including the Routes.php file.

I mainly used the command to send automated email with the link to a page in the application, and using the route_to function was a simple way to keep track of the routes.
Any suggestion on how to do this now in 4.3.2?
I don't recall in the upgrade instruction there was any information on how to do this.


Thanks.

After a quick check it seems that I can call "Services::routes()->loadRoutes();" and that loads all my custom routes in the spark command.

But not sure if that's the correct approach.


RE: How to pull routes in spark command - kenjis - 03-28-2023

See https://codeigniter.com/user_guide/installation/upgrade_430.html#mandatory-file-changes


RE: How to pull routes in spark command - ciUser43 - 03-28-2023

(03-28-2023, 05:07 PM)kenjis Wrote: See https://codeigniter.com/user_guide/installation/upgrade_430.html#mandatory-file-changes

Do you mean I should add likeĀ 

PHP Code:
require_once(SYSTEMPATH 'Config/Routes.php'
into all my commands?

Or are you saying spark commands aren't meant to access the routes at all? That would be strange if the support was provided and just suddenly broken without explanation.


RE: How to pull routes in spark command - kenjis - 03-28-2023

Sorry, I confused it with some kind of issue where the files were not updated enough.


RE: How to pull routes in spark command - yassine - 08-25-2023

Hey @kenjis, I'm having the same issue: route_to stopped working in spark commands from v4.3

I'm wondering if this was fixed in newer versions. Or is there any other way to access named routes in spark commands?

Also, thank you for your work on CodeIgniter!


EDIT: saw that @ciUser43 found a way to load routes using:

PHP Code:
Services::routes()->loadRoutes(); 



RE: How to pull routes in spark command - user44953432 - 08-27-2023

"php spark routes" is one way I came across in documentation to see the routes configured. Not sure if it will help in your situation,


RE: How to pull routes in spark command - kenjis - 08-27-2023

Yes, you need to load the routes with Services::routes()->loadRoutes() now.

Maybe route_to() should load the route, though.