Practical Web Data Patterns
Route Matches
Match a path to a handler label.
Route Matches
route_match.php
<?php
$path = ;
$handler = "not_found";
if ($path === "/users") {
$handler = "users_index";
} elseif ($path === "/health") {
$handler = "health_check";
}
echo "path=" . $path . "\n";
echo "handler=" . $handler . "\n";
<?php
$path = ;
$handler = "not_found";
if ($path === "/users") {
$handler = "users_index";
} elseif ($path === "/health") {
$handler = "health_check";
}
echo "path=" . $path . "\n";
echo "handler=" . $handler . "\n";
<?php
$path = ;
$handler = "not_found";
if ($path === "/users") {
$handler = "users_index";
} elseif ($path === "/health") {
$handler = "health_check";
}
echo "path=" . $path . "\n";
echo "handler=" . $handler . "\n";
route-match
A small router maps a path to a handler. The lesson uses fixed path strings instead of a live server request.