AltoRouter
AltoRouter copied to clipboard
Pass parameter just after domain
Hi All, I am using altorouter for routing the paths but I want to use the parameters just after the domain like http://example.com/category-name which when executed gives the category name to the PHP file which then loads the data according to category name. My index file is like this:
` require 'lib/AltoRouter.php';
$router = new AltoRouter();
$router->setBasePath('example.com/');
$router->map( 'GET', '', function() {
require __DIR__ . '/home.php';
});
$router->map( 'GET', '/', function() {
require __DIR__ . '/home.php';
});
$router->map( 'GET', '/home', function() {
require __DIR__ . '/home.php';
});
$router->map( 'GET', '/directory', function() {
require __DIR__ . '/directory.php';
});
$router->map( 'GET', '/[*:name]', function() {
require __DIR__ . '/category.php';
});
$match = $router->match();
if($match && is_callable( $match['target'] )) {
call_user_func($match['target'], $match['params']);
}
else {
echo "not working";
};
`
I have found one issue similar to this https://stackoverflow.com/questions/36351681/altorouter-cant-figure-out-how-to-route-correctly-php
I want results like this described in this issue. Can anyone help me out in this issue?
You probably should not include the domain name in the base path.