-
Notifications
You must be signed in to change notification settings - Fork 1
Routes
Joseph Mancuso edited this page May 22, 2017
·
4 revisions
Routing is an extremely important feature to have in a website. It allows you to render pages without having them physically on the server
// application/Routes.php
Route::get("path/to/url", function(){
Render::view("appname.template");
});
You can also send any variables to the template
// application/Routes.php
Route::get("path/to/url", function(){
Render::view("appname.template",
[
"variable" => "value",
"another_variable" => "value"
]
);
});
You can also get certain values from the URL and pass them to your view or use them in your Closure
// application/Routes.php
// URL: website.com/baseball/player/123/
Route::get("baseball/player/{id}/", function($id){
// $id is now accessible : $id = 123
$model = new model("database");
$player = $model->filter(" id = '$id' ");
Render::view("appname.template",
[
"player" => $player
]
);
});
You can also use the $
sign at the end of the url
// matches: website.com/baseball/player/
// does not match: website.com/baseball/player/123
Route::get("baseball/player/$" ...);
// matches: website.com/baseball/player/123
// does not match: website.com/baseball/player/
Route::get("baseball/player/{id}" ...);