AltoRouter icon indicating copy to clipboard operation
AltoRouter copied to clipboard

Pass parameter just after domain

Open pcexpert247 opened this issue 7 years ago • 1 comments

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?

pcexpert247 avatar Apr 27 '18 07:04 pcexpert247

You probably should not include the domain name in the base path.

koenpunt avatar May 12 '18 18:05 koenpunt