Polavi application uses FastRoute to handle routing. You can check this page for more information.

How to Polavi route look like?

Please take a look this example of a route

$router->addAdminRoute('category.grid', 'GET', '/categories', [

You can see above code in routes.php file of each module. It registers a route. Let's go to its detail

$router is an object of Polavi\Services\Routing\Router class. $router->addAdminRoute() is a method to register an Admin route. There is another method named $router->addSiteRoute() to add a site route. The above methods take 4 arguments.

  • string $id: This argument is route identify. It will be used when you need to generate URL for that route using this method $router->generateUrl().
  • $method: This is the HTTP method. It can be a string like "GET" or an array like ["GET", "POST"]
  • string $pattern: This is the route pattern.
  • array $middleware: This is a list of middleware that will be executed. This list can be changed later using event dispatcher. We described in this document

How to register a new route?

To have a new route you need to have a module. You can check about module here And inside your module, you add your route using routes.php file as we described above.

How to generate a URL for a route?

You can generate a url for a route using this method of router object $router->generateUrl() That method takes 3 arguments:

  • string $routeId: This argument is route identify.
  • array $params = []: This is list of params of route
  • array $query: List of query (?a=b).