like many other frameworks, if you are using router with it's default behavior, there is a one-to-one relationship between a URL string and its corresponding controller class/method. The segments in a URI normally follow this pattern: :: example.com/controller/method/param example.com/controller/method/param1/param2
When the URL is composed of a single part, corresponding to the name of a controller, the index method of the controller is automatically called :
URL : :: example.com/Products example.com/Products/index
Controller :
class Products extends ControllerBase{
public function index(){
//Default action
}
}
If the requested method requires parameters, they must be passed in the URL:
Controller :
class Products extends ControllerBase{
public function display($id){}
}
Valid Urls : :: example.com/Products/display/1 example.com/Products/display/10/ example.com/Products/display/ECS
The called method can accept optional parameters.
If a parameter is not present in the URL, the default value of the parameter is used.
Controller :
class Products extends ControllerBase{
public function sort($field,$order="ASC"){}
}
Valid Urls : :: example.com/Products/sort/name (uses "ASC" for the second parameter) example.com/Products/sort/name/DESC example.com/Products/sort/name/ASC
On Unix systems, the name of the controllers is case-sensitive.
Controller :
class Products extends ControllerBase{
public function caseInsensitive(){}
}
Urls : :: example.com/Products/caseInsensitive (valid) example.com/Products/caseinsensitive (valid because the method names are case insensitive) example.com/products/caseInsensitive (invalid since the products controller does not exist)
The router
and annotations of controller classes allow you to customize URLs.