Laravel basic workflow route-> controller-> view workflow
The basic workflow is as follows:
-
The general laravel routing method directly writes anonymous functions into the routing.
Route: get ('/', function () {return view ('Welcome '); // welcome is the file name of laravel's blade template engine })
Traditionally, php is written based on the file directory location.
/Blog/index. php/blog/about. phpThe access time is http: // localhost/blog/index. php. now, you can use route to centrally control
-
Since laravel's route supports controller, you can write it like this, pass in a controller, and use @ to call the methods in the controller. Therefore, you can write the anonymous function in this way.
Route: get ('/', 'sitecontroller @ index '); Comparison:
Route: get ('/', function () {return view ('Welcome '); // This is the Route of the anonymous function}) Route: get ('/', 'sitecontroller @ index'); // This is the route using the controller
You can create a controller using the command line.
php artisan make:controller SiteControllerController created successfully.
Write a method index () called just now in the newly created controller ()
Class SiteController extends Controller // All controllers are inherited from the controller class {// public function index () {return view ('Welcome '); // This index method directly returns a view. The view file is welcome. blade. php }}
-
Blade engine template of view
- The blade engine template is generally stored in the app/resource/views Directory. the template ends with. blade. php.
- The view command reads app/resource/views as the root directory by default, so you can directly view ('Welcome '), this indicates that a view named "welcome" under the app/resource/views directory is displayed. blade. php files. view can directly identify blade. php, so it can be omitted.
- The blade template file is actually an html file, but you can write some template syntaxes supported by laravel to implement data interaction.
This article was created by Peter yuan and is licensed on the Chinese mainland using the signature-non-commercial use 2.5. You need to contact the author before reprinting and referencing, and sign the author and indicate the source of the article. A teenager like a god» basic laravel workflow