Inside this article we will see how to check all routes of application in cakephp 4. Article contains classified information about routes lookover.
Routes are generally added to routes.php file from /config folder. We will see how to check all available routes of application via bin/cake command. How to read all application routes we will see here in a detailed way.
Learn More –
- Authentication Tutorial in CakePHP 4
- CakePHP 4 – Change Default PORT of Development Server
- CakePHP 4 Custom Validation Rule For Form Inputs
- CakePHP 4 Error: Database driver Cake\Database\Driver\Sqlite cannot be used
Let’s get started.
CakePHP 4 Installation
To create a CakePHP project, run this command into your shell or terminal. Make sure composer should be installed in your system.
$ composer create-project --prefer-dist cakephp/app:~4.0 mycakephp
Above command will creates a project with the name called mycakephp.
How To Add Routes
In CakePHP 4, to add routes we prefer routes.php file from /config folder.
For example,
//.. $routes->scope('/', function (RouteBuilder $builder) { // Student Routes $builder->connect('/add-student', ['controller' => 'Students', 'action' => 'addStudent']); $builder->connect('/edit-student/:id', ['controller' => 'Students', 'action' => 'editStudent'], ["pass" => ["id"]]); $builder->connect('/list-students', ['controller' => 'Students', 'action' => 'listStudents']); // Ajax Routes $builder->connect('/ajax-add-student', ['controller' => 'Ajax', 'action' => 'ajaxAddStudent']); $builder->connect('/ajax-edit-student', ['controller' => 'Ajax', 'action' => 'ajaxEditStudent']); $builder->connect('/ajax-delete-student', ['controller' => 'Ajax', 'action' => 'ajaxDeleteStudent']); }); //...
Above routes we have added into routes.php.
Check Application Routes
We have few options to check all available routes of application.
- By routes.php file
- By bin/cake command
We can see routes.php file directly for all available application routes.
Alternative way,
bin/cake Command
Here, we need to type this command to see routes as –
$ bin/cake routes
In the above screenshot we can see the list of available routes. This will give the idea about all routes including hidden routes which you don’t find inside routes.php file.
We hope this article helped you to learn about CakePHP 4 How To Check All Routes of Application in a very detailed way.
Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.
If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.