Route (routing) –>controller (Controller) –>view (view) workflow
The basic work flow is as follows
General Laravel routing, write anonymous functions directly inside the route
Route::get ('/', function () {return view (' Welcome ');//welcome is the file name of Laravel blade template engine})Traditionally, PHP is written according to the file directory location.
/blog/index.php/blog/about.phpAccess is http://localhost/blog/index.php, now unified control via route
-
Because Laravel's route supports the controller, it can be written like this, passing in a controller and then using @ To invoke the method inside the controller, so you can change the anonymous function to this way
Route::get ('/', ' sitecontroller@index ');
Compare:
route::get ('/', function () {return view (' welcome ');//This is the route of the anonymous function }) Route::get ('/', ' sitecontroller@index '); This is a route using the controller
To create a controller from the command line
php Artisan Make:controller Sitecontrollercontroller created successfully.
In the controller you just created, write a method that you just called index ()
class Sitecontroller extends Controller//All controllers are inherited from controller this class {//Public function index () {return view (' Welcome '); In this index method, a view view is returned directly with the file welcome.blade.php}}
About the Blade Engine template for view view
- Blade engine templates are typically stored under the App/resource/views directory, with templates ending with. blade.php
- The view command reads App/resource/views as the root directory by default, so you can view it directly (' welcome '), meaning that the view is in app/resource/ Views this directory of a file named welcome.blade.php, view can be directly recognized blade.php, so can be omitted.
- Blade template file is actually an HTML file, but can write some Laravel support template syntax, to achieve data interaction
This article was authored by Peteryuan and licensed under the Attribution-NonCommercial use of 2.5 mainland China. Please contact the author and the author and indicate the source of the article before reprint or citation. God-like teenager»laravel basic work flow