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