Created
January 2, 2019 06:17
-
-
Save kobi/09eaeeecb3406b193a84a674218798a9 to your computer and use it in GitHub Desktop.
Based on example on https://github.com/dannyvankooten/AltoRouter/tree/master/examples/basic , Stack Overflow question https://stackoverflow.com/q/53996361/7586
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body {background-color: dodgerblue;} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require 'AltoRouter.php'; | |
$router = new AltoRouter(); | |
$router->setBasePath('/AltoRouter/examples/basic'); | |
$router->map('GET|POST','/', 'home#index', 'home'); | |
$router->map('GET','/users/', array('c' => 'UserController', 'a' => 'ListAction')); | |
$router->map('GET','/users/[i:id]', 'users#show', 'users_show'); | |
$router->map('POST','/users/[i:id]/[delete|update:action]', 'usersController#doAction', 'users_do'); | |
$router->map('GET','/bootstrapcss','example.css','bootstrapcss'); | |
// match current request | |
$match = $router->match(); | |
if($match['name'] === 'bootstrapcss'){ | |
header("Content-Type: text/css"); | |
$fileName = $match['target']; | |
echo file_get_contents($fileName); | |
return; | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<link rel="stylesheet" type="text/css" href="<?php echo $router->generate('bootstrapcss'); ?>" /> | |
</head> | |
<body> | |
<h1>AltoRouter</h1> | |
<h3>Current request: </h3> | |
<pre> | |
Target: <?php var_dump($match['target']); ?> | |
Params: <?php var_dump($match['params']); ?> | |
Name: <?php var_dump($match['name']); ?> | |
</pre> | |
<h3>Try these requests: </h3> | |
<p><a href="<?php echo $router->generate('home'); ?>">GET <?php echo $router->generate('home'); ?></a></p> | |
<p><a href="<?php echo $router->generate('bootstrapcss'); ?>">CSS <?php echo $router->generate('bootstrapcss'); ?></a></p> | |
<p><a href="<?php echo $router->generate('users_show', array('id' => 5)); ?>">GET <?php echo $router->generate('users_show', array('id' => 5)); ?></a></p> | |
<p><form action="<?php echo $router->generate('users_do', array('id' => 10, 'action' => 'update')); ?>" method="post"><button type="submit"><?php echo $router->generate('users_do', array('id' => 10, 'action' => 'update')); ?></button></form></p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment