Laravel learning day 1 (create a laravel project, route, view, and blade template)

Source: Internet
Author: User
: This article mainly introduces the first day of Laravel learning (creating a laravel project, route, view, and blade template). If you are interested in the PHP Tutorial, refer to it. Create a laravel project

Composer create-project laravel/laravel learnlv 4. 1 .*

View help: composer create-project

Use the artisan tool

Generate key: php artisan key: genrate, for more commands see: http://blog.luoyunshu.com/laravel-cheatsheet

Routing

Route. php:

/*

|--------------------------------------------------------------------------

| Application Routes

|--------------------------------------------------------------------------

|

| Here is where you can register all of the routes for an application.

| It's a breeze. Simply tell Laravel the URIs it should respond to

| and give it the Closure to execute when that URI is requested.

|

*/

// Pass the parameter to the controller, Route: get ('/{id }')

// Two formats: 1. Route: get ('/', function (){})

// 2. Route: get ('/', array ('as' => 'home _ route ', function () {}) as defined Route name

Route::get('/', array('as'=>'home_route', function()

{

// Pass parameters to the view

// Method 1:

//$var = 'hello world';

//return View::make('hello')->with('var', $var);

// Method 2

//$var = 'abcd';

//return View::make('hello', array('var'=>$var));

// Method 3

$var = 'def';

$view = View::make('index.hello');

$view->var = $var;

return $view;

}));

// Define the controller

Route::get('index', function()

{

$arr = array(

'yunshu',

'Yunshu'

);

return View::make('index.index', array('arr'=>$arr));

});

// Generate route URL and redirect

Route::get('test', function()

{

// Generate a URL

$url = URL::route('home_route');

//echo $url;

// Jump

return Redirect::route('home_route');

});

Blade layout

(master.blade.php):

@include('layout.header')

@yield('content')

@section('section')

Haha

@show

{-- Comment code --}}

@include('layout.footer')

index.blade.php:

@extends('layout.master')

{-- Use the master template --}}

{-- Use this part of content to fill the template --}}

@section('content')

@foreach($arr as $a)

{{ $a }}

@endforeach

{-- Create image --}}

{{ HTML::image('image/1.jpg') }}

@stop

{-- Overwrite or overwrite the content of the parent template --}}

@section('section')

{-- Get the content of the parent template using @ parent --}}

@parent

'Hi'

@stop

Code packaging:

http://files.cnblogs.com/files/luoyunshu/learnlv.zip

The above introduces the first day of Laravel learning (creating a laravel project, routing, view, and blade template), including some content, and hopes to help those who are interested in the PHP Tutorial.

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.