CakePHP 4 How To Check All Routes of Application

Share this Article
Reading Time: 3 minutes
360 Views

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 –

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.

Buy Me a Coffee

Online Web Tutor invites you to try Skillshare free for 1 month! Learn CakePHP 4, Laravel APIs Development, CodeIgniter 4, Node Js, etc into a depth level. Master the Coding Skills to Become an Expert in Web Development. So, Search your favourite course and enroll now. Click here to join.

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.

Was this post helpful?

Learn Web Development Courses Risk Free @ $5 only.
Web Development Courses @ $5