Using Router to Reverse Match Routes in CakePHP4

Using Router to Reverse Match Routes in CakePHP4

For example, if you have a route set for http://example.com/search, which routes, in this case, to Controller Articles, and Action search, the reverse route would send the user to http://example.com/search.

In our config/router.php, we have the following route:

$builder->connect('/search/*', ['controller' => 'Articles', 'action' => 'search']);

In our controller or view, add the the following - this will show the stated route as above, /search

use Cake\Routing\Router;
debug(Router::url(['controller'=>'Articles', 'action'=>'search'] ) );

 

For additional resources, visit the CakePHP CookBook:
https://book.cakephp.org/4/en/development/routing.html#quick-tour

Share this Post