Skip to content
PHP Logo

In PHP frameworks, is it common practice to use both custom routes and default routes for controller access?

In PHP frameworks, it is common practice to use a combination of custom routes and default routes for controller access. Custom routes allow for more specific and descriptive URLs to be mapped to controller actions, while default routes provide a fallback mechanism for accessing controllers without explicitly defining routes for each action. By utilizing both custom and default routes, developers can create a flexible and organized routing structure for their applications.

php
// Custom route for accessing a specific controller action
$router->add('/users/profile', 'UserController@profile');

// Default route for accessing controllers with dynamic parameters
$router->add('/{controller}/{action}/{id}', '{controller}@{action}');