Laravel 5 Basic Tutorials | | 2. Routing: Link to Controller-table seriousness
Intuitively, routing is used to parse the part of the address bar after the domain name.
Example: Baidu.com/lala
Note the/lala after the domain name, this is a routing rule. Routing rules allow us to flexibly control the scope and depth of user access, and can even be used for rights management in Laravel.
Create a route
Routing files
For example, if your Laravel project directory is called MySite, then the routing control file is in/mysite/app/http/routes.php
This file has only one rule at the beginning, like this (if you find more than one, it doesn't matter, anyway, no matter how much we will delete the rewritten, wayward (? ^?)):
This is a definition of the first page of the routing rules, that is, this rule allows us to see the default home page Laravel, that is, after the successful installation of the interface. (similar to below)
Route::get ('/', function () { return view (' Welcome ');});
Shameless hard wide into
Laravel 5 Video Tutorial Address-table serious lecture (can audition)
All courses: biaoyansu.com
Shameless hard wide out
First Route ~
Route::(' hello ', function () { return ' hello. ';});
Explanation: The first pass is the address of the route (example: +baidu.com/hello), the second argument is a function, and the smart one must be able to guess (mua~) This function is triggered when the route matches, if your current test address is +localhost:8888 then, Then when you enter +localhost:8888/hello in the browser address bar and then come to a low-key return you will see a low-key "Hello."
The attentive classmate may find that we are using return instead of ECHO, why can we print the string directly? Laravel is such a small vest, when he detects that you return directly to the string will use echo, more than that, when the returned array is detected Laravel will convert the array to JSON return (warm male one, identification completed).
Route::get (' Hello ', function () { return [ ' greet ' = ' hello ', ' name ' = ' xiaobeixin ' ];});
Will output:
Route-Pass parameters
What if we want to add a person's name dynamically after Hello?
Do this:
Route::get (' hello/{name} ', function ($name) { return ' hello '. $name. '.'; });
Address bar Pass parameter localhost:8888/hello/liming
Output:
So how to output an HTML file ray?
Don't worry, talk with the view back.