pclib  3.0.0
Lightweight PHP framework
PClib route

Route specify "path" to controller's action and can be used instead of plain href attribute.

Each route is translated to common url by function $app->geturl($route). Syntax of the route is similar to directory path. Basic syntax is "controller/action/parameters" which means:

Do "action" with "parameters" in application controller "controller". The purpose of routes is create clean, logical application structure and simple, easy and consistent way to navigate on this structure.

Examples:

  • route: "products/edit/id:100"
  • translated to: index.php?r=products/edit&id=100
  • description: edit product with id=100
  • route: "products/add"
  • translated to: index.php?r=products/add
  • description: add new product
  • route: "products"
  • translated to: index.php?r=products
  • description: default action - can be for example list of all products

For redirecting in your source code you can use function $app->redirect() Example:

$app->redirect("companies/edit/id:$id");

You can use routes in any template when you are creating link or button or even instead of form "action". Just use attribute "route" instead of "href". Examples:

<?elements
link productlist lb "List of products" route "products/list"
button edit lb "Edit product" route "products/edit/id:{ID}"
form route "products/{GET}"
?>

In template, you can use any template value as part of route - usually {ID}, {COMPANY_ID} or so.

Also you can put some additional variables into route with syntax "/variable:value". Examples:

  • route: "products/edit/id:100/s:1"
  • translated to: index.php?r=products/edit&id=100&s=1
  • route: "companies/type:$type/location:us"
  • translated to: index.php?r=companies&type=$type&location=us

It's possible pass GET variables through route. Just add to the end of the route "/{GET}" for passing all GET variables or "/variable:{GET.variable}" for passing particular variable. Ex: route "products/edit/id:{GET.id}"