Menu

Class@Method calls
Working with controllers

Overview

Controllers

We can route to the class action like so:

$leaf->get('/(\d+)', '\App\Controllers\User@showProfile');

When a request matches the specified route URI, the showProfile method on the User class will be executed. The defined route parameters will be passed to the class method..

The method can be static or non-static. In case of a non-static method, a new instance of the class will be created.

If most/all of your handling classes are in one and the same namespace, you can set the default namespace to use on your router instance via setNamespace()

$leaf->setNamespace('\App\Controllers'); $leaf->get('/users/(\d+)', 'User@showProfile'); $leaf->get('/cars/(\d+)', 'Car@showProfile');

Next Steps

Re-routing to index.php
Simple Routing
Request
Response