How to easily list all routes that we have defined in our application with Zend Framework 2?
By "routes" I mean those which are defined in:
module/[moduleName]/config/module.config.php
under
'router' => array(
'routes' => array(
...
)
)
I need to list them all but I can't figure out how to do this easily and nor the documentation nor the forums helped me by now.
You can find the complete (merged) config or dump the Router itself. There is no way to export all route objects, so there I've to disappoint you.
To get the complete config, get it from the service locator:
// $sl instanceof Zend\ServiceManager\ServiceManager
$config = $sl->get('COnfig');
$routes = $config['router']['routes'];
If you want to view all routes just for debugging purposes, you can use var_dump
or similar on the router object:
// $sl instanceof Zend\ServiceManager\ServiceManager
$router = $sl->get('Router');
var_dump($router);
To get route instances you can build the routes yourself using the route plugin manager, but I am not sure that's the way you want to go...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With