Laravel basic workflow-php Tutorial

Source: Internet
Author: User
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. php

    The 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

    1. The blade engine template is generally stored in the app/resource/views Directory. the template ends with. blade. php.
    2. 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.
    3. 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

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.