CakePHP Routing

cakephp

In CakePHP, routing is the process of mapping URLs to controller actions. Routing allows you to create pretty, human-readable URLs that are more easily understood by both users and search engines.

Here’s an example of a basic route in CakePHP:

$routes->connect('/posts/:id', ['controller' => 'Posts', 'action' => 'view'], ['id' => '\d+', 'pass' => ['id']]);

This route will match URLs like /posts/123 and pass the value 123 to the view action of the Posts controller as the id parameter. The :id part of the route is a placeholder that matches any digits (\d+), and the pass option specifies that the matched value should be passed to the action as a parameter.

You can define routes in the config/routes.php file of your CakePHP application. For more information about routing in CakePHP, you can refer to the documentation at https://book.cakephp.org/4/en/development/routing.html.