[Laravel] The fundamental use of laravel

Source: Internet
Author: User
[Laravel] Basic use of Laravel

[Laravel] Basic HTTP routing for Laravel

Use Laravel's basic route, implement GET request response, find file app/http/routes.php

Call the route's static method get (), implement get response, parameter: path of type string, anonymous functions function () {}

Inside the anonymous function, returns the string data

Implementation of Post,put,delete's request, IBID.

Implement the Get pass parameter route, call the route's static method get (), Parameter: path, anonymous function

Path, curly brace wrap parameter name, not including $, for example: '/user/{id} '

anonymous function, receive parameter, for example: function ($id) {}

[Laravel] Laraval's Basic controller

Under the App/http/controllers directory, create a new index/indexcontroller.php

Define namespaces, Namespace App\http\controllers\index

Introduction of controller base controllers, use App\http\controllers\controller

Define Indexcontroller inherit Controller

Implementation method index, return data

Defines the behavior of the route-specific controller, for example: Route::get ("/index", "Index\[email protected]");

Note In the namespace section, the newly created controller is under the root namespace, adding its own newly added namespace when specified

[Laravel] Basic view of Laravel

Under Directory resources/views/, create a index/index.php

Use Function view () in the controller to invoke the template, Parameters: File path (. delimited directory), data

Routing: routes.php

 Php/*|--------------------------------------------------------------------------| Routes file|--------------------------------------------------------------------------| | Here's where you'll register all of the routes in an application.| It ' s a breeze. Simply tell Laravel the URIs it should respond to| and give it the controller to call when that URI is requested.|*//*test get post*/Route::get ('/', function () {$url=url ("Index"); return"Hello World". $url; //return view (' Welcome ');}); Route::p Ost ("/post", function () {return"Test Post";});/*Passing Parameters*/Route::get ("/user/{id}", Function ($id) {returnUser. $id;});/*using the Controller*/Route::get ("/index", "Index\[email protected]");/*|--------------------------------------------------------------------------| Application routes|--------------------------------------------------------------------------| | This route group applies the "Web" middleware group to every route| It contains. The "web" middleware Group is defined in your http| Kernel and includes session state, CSRF protection, and more.|*/Route::group ([' Middleware ' = [' web ']], function () {//});

Controller: indexcontroller.php

 
  Phpnamespace App\http\controllers\index;use App\http\controllers\controller; class extends controller{    public  function Index () {        $data=Array ();        $data [' title ']= "index Controller";         return view ("Index.index", $data);}    }

Template: index.php

    <Body>        <Divclass= "Container">            <Divclass= "Content">                <Divclass= "title"> 
    php echo $title; ?>  
     div> 
      div> 
       div>   
        body>  
         
            
               
 

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