Introduction to Laravel 5 framework learning routes, controllers and views, laravel framework_PHP tutorial

WBOY
Release: 2016-07-13 09:57:41
Original
1016 people have browsed it

Laravel 5 framework learning route, controller and view introduction, laravel framework

View app/Http/routes.php

Copy code The code is as follows:
Route::get('/', 'WelcomeController@index');

@ is a delimiter, preceded by the controller and followed by the action, which means that when the user requests url /, the index method in the controller WelcomeController is executed

Copy code The code is as follows:
app/http/controllers/welcomecontroller.php
public function index()
{
return view('welcome');
}

Currently, a view is returned by default. The name of the view is welcome, which is actually welcome.blade.php. Blade is the view template of laravel.

You can view `resources/views/welcome.blade.php

Modify welcomecontroller.php

Copy code The code is as follows:
public function index()
{
// return view('welcome');
return 'hello, laravel';
}

Test in your browser and get a simple feedback.

We create a new route and add:

in routes.php

Copy code The code is as follows:
Route::get('/contact', 'WelcomeController@contact');

You can create a new route, but for now we still use the default controller directly and add:

to WelcomeController.php

Copy code The code is as follows:
public function contact() {
Return 'Contact Me';
}

Test the newly added route in the browser.

We can return 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 consider 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 only need to return view('forum/xxx'), or the simple and clear way is: return view('forum.xxx'). 😄

We return to a page

Copy code The code is as follows:
public function contact() {
Return view('pages.contact');
}

Create the pages directory under the views directory, and then create contact.blade.php

Copy code The code is as follows:




Document


Contact




The above is the entire content of this article. I hope it will be helpful to everyone learning Laravel5.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/980219.htmlTechArticleLaravel 5 framework learning route, controller and view introduction, laravel framework view app/Http/routes.php copy The code is as follows: Route::get('/', 'WelcomeController@index'); @ is a...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template