Added leading slash to routes
This commit is contained in:
parent
11d0aa2c7a
commit
8699df0060
|
@ -11,9 +11,9 @@ class Route{
|
||||||
$parsed_url = parse_url($_SERVER['REQUEST_URI']);//Parse Uri
|
$parsed_url = parse_url($_SERVER['REQUEST_URI']);//Parse Uri
|
||||||
|
|
||||||
if(isset($parsed_url['path'])){
|
if(isset($parsed_url['path'])){
|
||||||
self::$path = trim($parsed_url['path'],'/');
|
self::$path = $parsed_url['path'];
|
||||||
}else{
|
}else{
|
||||||
self::$path = '';
|
self::$path = '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
14
index.php
14
index.php
|
@ -11,43 +11,43 @@ Config::set('basepath','');
|
||||||
Route::init();
|
Route::init();
|
||||||
|
|
||||||
//base route (startpage)
|
//base route (startpage)
|
||||||
Route::add('',function(){
|
Route::add('/',function(){
|
||||||
//Do something
|
//Do something
|
||||||
echo 'Welcome :-)';
|
echo 'Welcome :-)';
|
||||||
});
|
});
|
||||||
|
|
||||||
//base route
|
//base route
|
||||||
Route::add('index.php',function(){
|
Route::add('/index.php',function(){
|
||||||
//Do something
|
//Do something
|
||||||
echo 'You are not realy on index.php ;-)';
|
echo 'You are not realy on index.php ;-)';
|
||||||
});
|
});
|
||||||
|
|
||||||
//simple route
|
//simple route
|
||||||
Route::add('test.html',function(){
|
Route::add('/test.html',function(){
|
||||||
//Do something
|
//Do something
|
||||||
echo 'Hello from test.html';
|
echo 'Hello from test.html';
|
||||||
});
|
});
|
||||||
|
|
||||||
//complex route with parameter
|
//complex route with parameter
|
||||||
Route::add('user/(.*)/edit',function($id){
|
Route::add('/user/(.*)/edit',function($id){
|
||||||
//Do something
|
//Do something
|
||||||
echo 'Edit user with id '.$id.'<br/>';
|
echo 'Edit user with id '.$id.'<br/>';
|
||||||
});
|
});
|
||||||
|
|
||||||
//accept only numbers as the second parameter. Other chars will result in a 404
|
//accept only numbers as the second parameter. Other chars will result in a 404
|
||||||
Route::add('foo/([0-9]*)/bar',function($var1){
|
Route::add('/foo/([0-9]*)/bar',function($var1){
|
||||||
//Do something
|
//Do something
|
||||||
echo $var1.' is a great number!';
|
echo $var1.' is a great number!';
|
||||||
});
|
});
|
||||||
|
|
||||||
//long route
|
//long route
|
||||||
Route::add('foo/bar/foo/bar',function(){
|
Route::add('/foo/bar/foo/bar',function(){
|
||||||
//Do something
|
//Do something
|
||||||
echo 'hehe :-)<br/>';
|
echo 'hehe :-)<br/>';
|
||||||
});
|
});
|
||||||
|
|
||||||
//crazy route with parameters (Will be triggered on the route pattern above too because it matches too)
|
//crazy route with parameters (Will be triggered on the route pattern above too because it matches too)
|
||||||
Route::add('(.*)/(.*)/(.*)/(.*)',function($var1,$var2,$var3,$var4){
|
Route::add('/(.*)/(.*)/(.*)/(.*)',function($var1,$var2,$var3,$var4){
|
||||||
//Do something
|
//Do something
|
||||||
echo 'You have entered: '.$var1.' / '.$var2.' / '.$var3.' / '.$var4.'<br/>';
|
echo 'You have entered: '.$var1.' / '.$var2.' / '.$var3.' / '.$var4.'<br/>';
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user