라라벨 프로젝트 생성
composer create-project laravel/laravel learnlv 4.1.*
도움말 보기: 작곡가 생성 프로젝트
장인 도구 사용
키 생성:php artisan 키:genrate, 자세한 명령은 http://blog.luoyunshu.com/laravel-cheatsheet를 참조하세요
라우팅
route.php:
<code><span><?<span>php</span></span>
<span>/*</span>
<code><span>|--------------------------------------------------------------------------</span>
/*
<span>| Application Routes</span>
<코드>
<code><span>|--------------------------------------------------------------------------</span>
<p>| 신청 경로<code><span>|</span>
<코드><span>| Here is where you can register all of the routes for an application.</span>
|---------------------------- ---------------------
<span>| It's a breeze. Simply tell Laravel the URIs it should respond to</span>
</p>|<p>
<span>| and give it the Closure to execute when that URI is requested.</span>
<p>| 여기에서 애플리케이션의 모든 경로를 등록할 수 있습니다.<code><span>|</span>
<code><span>*/</span>
| Laravel에 응답해야 하는 URI를 알려주기만 하면 됩니다.
<span>//向控制器传递参数,Route::get('/{id}')</span>
</p>| 해당 URI가 요청될 때 실행할 클로저를 제공합니다.<p>
<span>//两种格式:1、Route::get('/', function(){})</span>
<p>|<code><span>// 2、Route::get('/', array('as'=>'home_route',function(){})) as的定义路由名称</span>
<code><span>Route<span>::<span>get<span>(<span>'/'<span>,<span> array<span>(<span>'as'<span>=><span>'home_route'<span>,<span> <span>function<span>()</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
*/
<span>{</span>
<span> <span>//向视图传递参数</span></span>
<p>//두 가지 형식: 1. Route::get('/', function(){})<code><span> <span>//方法一:</span></span>
<code><span> <span>//$var = 'hello world';</span></span>
// 2. Route::get('/', array('as'=>'home_route',function(){})) 정의된 경로 이름
<span> <span>//return View::make('hello')->with('var', $var);</span></span>
::<span> <span>//方法二</span></span>
get
'/'<span> <span>//$var = 'abcd';</span></span>
,
(<span> <span>//return View::make('hello', array('var'=>$var));</span></span>
'as'
'home_route'<span> <span>//方法三</span></span>
,
함수<span> $var <span>=<span> <span>'def'<span>;</span></span></span></span></span>
()
<span> $view <span>=<span> <span>View<span>::<span>make<span>(<span>'index.hello'<span>);</span></span></span></span></span></span></span></span></span>
<span> $view<span>-><span>var<span> <span>=<span> $var<span>;</span></span></span></span></span></span></span>
<span> <span>return<span> $view<span>;</span></span></span></span>
<span>}));</span>
<span>//定义控制器</span>
<code><span>Route<span>::<span>get<span>(<span>'index'<span>,<span> <span>function<span>()</span></span></span></span></span></span></span></span></span>
{
<span>{</span>
//뷰에 매개변수 전달<span> $arr <span>=<span> array<span>(</span></span></span></span>
<span> <span>'yunshu'<span>,</span></span></span>
//방법 1: <span> <span>'云舒'</span></span>
<span> <span>);</span></span>
//$var = 'hello world';<span> <span>return<span> <span>View<span>::<span>make<span>(<span>'index.index'<span>,<span> array<span>(<span>'arr'<span>=><span>$arr<span>));</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
<span>});</span>
//return View::make('hello')->with('var', $var);<span>//生成路由URL与跳转</span>
<span>Route<span>::<span>get<span>(<span>'test'<span>,<span> <span>function<span>()</span></span></span></span></span></span></span></span></span>
//방법 2<span>{</span>
<span> <span>//生成URL</span></span>
//$var = 'abcd';<span> $url <span>=<span> URL<span>::<span>route<span>(<span>'home_route'<span>);</span></span></span></span></span></span></span></span>
<span> <span>//echo $url;</span></span>
//return View::make('hello', array('var'=>$var));<span> <span>//跳转</span></span>
<span> <span>return<span> <span>Redirect<span>::<span>route<span>(<span>'home_route'<span>);</span></span></span></span></span></span></span></span></span>
//방법 3<span>});</span>
<p> $var <span data-wiz-span="data-wiz-span">=</span> </p>'def';<p></p>
<p></p>
<p></p>
<p></p>
<span>@include<span>(<span>'layout.header'<span>)</span></span></span></span>
=<span><body></span>
$view->var = $var;
반환 $view;
}));
//컨트롤러 정의
경로::get('index', 함수()
{
$arr = 배열(
'윤슈',
'윤슈'
);
return View::make('index.index', 배열('arr'=>$arr));
});
//라우팅 URL 생성 및 점프
경로::get('test', 함수()
{
//URL 생성
$url = URL::route('home_route');
//echo $url;
//점프
반환 리디렉션::경로('home_route');
});
블레이드 레이아웃
(master.blade.php):
@include('layout.header')
<본문>
<span> <span><div></span></span>
<span> <span><div></span></span>
<span> <span>@yield<span>(<span>'content'<span>)</span></span></span></span></span>
<span> <span></<span>div<span>></span></span>
<span> <span></<span>div<span>></span></span>
<span> <span><div></span></span>
<span> <span><div></span></span>
<span> <span>@section<span>(<span>'section'<span>)</span></span></span></span></span>
<span> <span>哈哈</span></span>
<span> <span>@show</span></span>
<span> <span></<span>div<span>></span></span>
<span> <span></<span>div<span>></span></span>
<span> <span>{{--<span> <span>注释代码--}}</span></span></span></span>
<span>@include<span>(<span>'layout.footer'<span>)</span></span></span></span>
index.blade.php:
<span>@extends<span>(<span>'layout.master'<span>)</span></span></span></span>
<span>{{--<span> <span>使用<span>master<span>模板<span> <span>--}}</span></span></span></span></span></span></span>
<span>{{--<span> <span>使用这部分内容填充模板<span> <span>--}}</span></span></span></span></span>
<span>@section<span>(<span>'content'<span>)</span></span></span></span>
<span> <span>@foreach<span>(<span>$arr <span>as<span> $a<span>)</span></span></span></span></span></span></span>
<span> <span>{{<span> $a <span>}}</span></span></span></span>
<span> <span>@endforeach</span></span>
<span> <span>{{--<span> <span>创建图片<span> <span>--}}</span></span></span></span></span></span>
<span> <span>{{<span> HTML<span>::<span>image<span>(<span>'image/1.jpg'<span>)<span> <span>}}</span></span></span></span></span></span></span></span></span></span>
<span>@stop</span>
<span>{{--<span> <span>覆盖或者重写父模板内容<span> <span>--}}</span></span></span></span></span>
<span>@section<span>(<span>'section'<span>)</span></span></span></span>
<span> <span>{{--<span> <span>拿到父模板的内容使用<span>@parent<span> <span>--}}</span></span></span></span></span></span></span>
<span> <span>@parent</span></span>
<span> <span>'你好呀'</span></span>
<span>@stop</span>
코드 패키징:
http://files.cnblogs.com/files/luoyunshu/learnlv.zip
위 내용은 관련 내용을 포함하여 Laravel 학습 첫날(laravel 프로젝트 생성, 라우팅, 뷰, 블레이드 템플릿)을 소개한 내용입니다. PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되길 바랍니다.