Welcome Guest, Not a member yet? Register   Sign In
help getting all routes in an array in controller
#5

(This post was last modified: 10-15-2023, 06:28 PM by kenjis.)

(12-12-2022, 07:26 PM)kenjis Wrote: Why do you want to get all routes?

In Routes.php I defined url identifier , like this

PHP Code:
$routes->get('(:any)''Go::go/$1', ['filter' => 'webratelimit']); 

When creating a new URL identifier, the identifier should not already exist as a valid CodeIgniter route. This is because if a URL identifier exists as a valid route, then it will conflict with the route, and the route will not be able to be accessed.

SO I need which rooutes are defined

I use this code to get all routes as array:


PHP Code:
$router Services::routes();
$routes $router->getRoutes();
dd($routes); 

but the returned array not contains all of defined routes is just get a scope of them and not all of them.

I solved it speicify which http verb I want  to get 

for example:
PHP Code:
$router Services::routes();
        $routes $router->getRoutes("post");
        dd($routes); 
and to get the get routes:

PHP Code:
$router Services::routes();
        $routes $router->getRoutes("get");
        dd($routes); 

because some times may be you are on post method and if you do $router->getRoutes you will get only post routes.

because I notice that using
PHP Code:
$router->getRoutes("*");
//see codeigniter4/framework/system/Router/RouteCollection.php line 193 

will not return any thing
Reply


Messages In This Thread
RE: help getting all routes in an array in controller - by mshannaq - 10-15-2023, 07:04 AM



Theme © iAndrew 2016 - Forum software by © MyBB