Laravel Basic Work Flow

Source: Internet
Author: User

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.php

    Access 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

    1. Blade engine templates are typically stored under the App/resource/views directory, with templates ending with. blade.php
    2. 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.
    3. 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

  • 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.