Laravel 5 Basics (ii)-Introduction to routing, controllers, and views

Source: Internet
Author: User
    • Viewapp/Http/routes.php
Route::get('/', 'WelcomeController@index');

@ is a qualifier, preceded by a controller, followed by an action, indicating that the index method in the controller Welcomecontroller is executed when the user requests the URL/

    • app/http/controllers/welcomecontroller.php
public function index(){return view('welcome');}

Currently returns a view by default, the name of the view is welcome, and the Welcome.blade.php,blade is actually a laravel view template.

    • can view ' resources/views/welcome.blade.php

    • Modify welcomecontroller.php

public function index(){//    return view('welcome');return 'hello, laravel';}
在浏览器中测试,得到一个简单的反馈。
    • We create a new route, which is added in routes.php:
Route::get('/contact', 'WelcomeController@contact');

You can create a new route, but now we are using the default controller directly, adding it in welcomecontroller.php:

public function contact() {    return 'Contact Me';}
在浏览器终测试新增加的路由。
    • We can return a simple string, or we can return a JSON or HTML file, and all of the view files are stored in resource->views.
      For example return view('welcome') , we do not need to consider the path or add the. blade.php extension, and the framework automatically completes for us. If you need subdirectories in the views directory, such as the Views/forum subdirectory, you only need return view('forum/xxx') to, or follow the simple and clear way: return view('forum.xxx') .??

    • We return to a page

public function contact() {    return view('pages.contact');}
    • Create the pages directory under the Views directory and create the contact.blade.php
    
  
       Document

Contact

The above describes the Laravel 5 Basic (ii)-routing, Controller and view introduction, including aspects of the content, I hope to be interested in PHP tutorial friends helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.