Annotated Router
Less than 1 minute
Annotated Router
Caution
The annotated router is deprecated and will be removed in a future release. Use the attribute router instead.
The annotated router uses annotations in controller classes to define routes. This method extends the advanced router, providing a more structured and organized approach to routing.
Defining Routes
To define a route, add the @route annotation to the controller class or method. The annotation accepts the following parameters:
$route: The URL pattern.$method(optional): The HTTP method (GET, POST, PUT, DELETE).
Example:
namespace App\Controller;
use Hazaar\Controller\Action;
/**
* @route("/api/v1/product/list", methods={"GET"})
*/
class Product extends Action {
public function list() {
// List products
}
}Route Parameters
Define route parameters in the URL pattern using curly braces.
Example:
/**
* @route("/api/v1/product/{int:id}", methods={"GET"})
*/
public function getProduct(int $id) {
// Retrieve the product with the specified ID
}Configuration (app.php)
<?php
return [
'development' => [
'router' => [
'type' => 'annotated'
]
]
];For route parameters and response types, see the routing overview.