URI Routing - pecesama/FlavorPHP GitHub Wiki
In the routes.php
with the follow function you can add a custom routing in FlavorPHP.
<?php
$this->add($expectedRute, $handleRute);
?>
Params:
-
String
$expectedRute
is an string with uri format, can be a regex. -
Mixed
$handleRute
must be and array with keysarray("controller" => "", "action" => "", $param => "")
or a string with the formatcontroller/action/$1/$2
.
Single action
<?php
$this->add("about", "index/about");
$this->add("tos", "index/tos");
$this->add("privacy", "index/privacy");
$this->add("signin", "index/signin");
$this->add("store/setup/name", "store/setup_name");
$this->add("store/setup/listings", "store/setup_listings");
$this->add("store/setup/payments", "store/setup_payments");
$this->add("store/setup/open", "store/setup_open");
?>
Action with one parameter
<?php
$this->add("store/orders/view/([0-9]*)", array("controller" => "store", "action" => "orders_view", "params" => '$1'));
$this->add("store/orders/refund/([0-9]*)", array("controller" => "store", "action" => "orders_refund", "params" => '$1'));
$this->add("store/orders/shipped/([0-9]*)", array("controller" => "store", "action" => "orders_shipped", "params" => '$1'));
?>
<?php
# Examples
// Array
$this->add("store/orders/view/([0-9]*)", array("controller" => "store", "action" => "orders_view", "params" => '$1'));
// String
$this->add("store/orders/view/([0-9]*)", 'store/orders_view/$1');
?>
Action with multiple parameters
<?php
// Array
$this->add("example/segment2/([0-9]*)/([0-9]*)", array('controller' => "MyController", 'action' => "index", 'params' => "$1/$2"));
// String
$this->add("store/orders/view/([0-9]*)/([0-9]*)", 'store/orders_view/$1/$2');
?>
Custom params order
<?php
// Diferent param order
$this->add("store/branch/([0-9]*)/orders/view/([0-9]*)", array('controller' => "MyController", 'action' => "index", 'params' => "$1/$2"));
?>