PHP laravel Framework Learning Notes (i) basic working principle

Source: Internet
Author: User

Original Blog Link: http://www.cnblogs.com/bitch1319453/

After the installation laraver is complete, enter the Laravel directory in cmd and use the command PHP artisan serve to open the 8000 port server

Then briefly describe the Laraver workflow. This workflow includes page authoring and passing parameters, so you can do some basic work.

Start Page

Unlike other frameworks, there is a route option in the framework. Open app/http/request/route.php and you will see

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here's where you can register any of the routes for an application.
| It ' s a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when the that URI is requested.
|
*/

Route::get ('/', function () {
Return view (' Welcome ');
});

View (' Welcome ') is the localhost:8000 page. You can return a string directly in the route, which returns a string page.

Check view, open Resource/view, Discover welcome.blade.php. This is the page returned by return, Blade seems to refer to the use of the template

The simplest and most brutal, we can add an anonymous function directly to the route (the anonymous function (Anonymous functions), also called the closure function (closures), allows temporary creation of a function without a specified name. The value most often used as the callback function (callback) parameter. Of course, there are other applications as well. )

Create a new page processing method using anonymous functions

If you first create a site folder in view, create a about.blade.php under the folder, we want to show that it can be written like this

Route::get ('/about ', function () {    return view (' Site/about ');});

Open Browser input localhost:8000/about can see this page

using a controller to create a new page processing method

Because it is bad practice to use anonymous functions for each view, we can use a controller to avoid excessive creation of anonymous functions

In the case where your laravel is composer created, you can create a controller with commands such as PHP artisan Make:controller name. Open App/http/controller and you'll find something you just created with the command line. Now I'll give you an example of using it.

Add in route.php, where Sitecontroller is the name you created, @ represents the method in call Sitecontroller

Route::get ('/about ', ' [email protected] ');

Add a function to the Sitecontroller index

<?phpnamespace app\http\controllers;use illuminate\http\request;use App\http\requests;class SiteController Extends controller{    //Public    function Index () {        return view (' Site/about ')->with (            [' sname ' =] Fuck ', ' bitchname ' = ' asshole '        );}    }

Well, it still returns a view, where with the two parameters sname and Bitchname are passed.

Then there's site/about.blade.php, a simple page.

<! DOCTYPE html>

The input localhost:8000/about can display asshole fuck asshole, proving that the controller was used successfully. By the way, Blade also has a lot of magic, @extend (' name ') can inherit the contents of the name, {{}} is also the escape notation provided by Blade, in addition to {{!! var!}} The notation is not escaped.

PHP laravel Framework Learning Notes (i) basic working principle

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.