In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to understand Laravel 5 framework routing, controller and view introduction", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's take you to learn "How to understand Laravel 5 framework routing, controller and view introduction"!
View app/Http/routes.php
The copy code is as follows:
Route::get('/', 'WelcomeController@index');
@ is a delimiter, preceded by controller, followed by action, indicating that when the user requests url /, the index method in the controller WelcomeController is executed.
The copy code is as follows:
app/http/controllers/welcomecontroller.php
public function index()
{
return view('welcome');
}
The current default returns a view called welcome, which is actually welcome.blade.php, blade is a view template for laravel.
You can view `resources/views/welcome.blade.php
Modify welcomcontroller.php
The copy code is as follows:
public function index()
{
// return view('welcome');
return 'hello, laravel';
}
Test it in the browser and get a simple feedback.
Let's create a new route and add to routes.php:
The copy code is as follows:
Route::get('/contact', 'WelcomeController@contact');
You can create a new route, but for now we'll just use the default controller and add it to WelcomeController. php:
The copy code is as follows:
public function contact() {
return 'Contact Me';
}
Test the newly added route in the browser terminal.
We can return either a simple string or a json or html file. All view files are stored in resource->views.
For example: return view ('welcome ') , we don't need to think about the path and don't add the. blade.php extension, the framework does it for us automatically. If you need a subdirectory in the views directory, such as the views/forum subdirectory, you just need to return view ('forum/xxx'), or simply and explicitly return view ('forum.xxx').
We return to a page
The copy code is as follows:
public function contact() {
return view('pages.contact');
}
Create a pages directory under the views directory and create contact.blade.php
The copy code is as follows:
Document
Contact
At this point, I believe that everyone has a deeper understanding of "how to understand Laravel 5 framework routing, controller and view introduction", so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.