创建laravel项目
composer create-project laravel/laravel learnlv 4.1.*
查看帮助:composer create-project
職人の工具を使用する
生成キー:php 職人キー: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>
<コード>|申請ルート<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>
|ここで、アプリケーションのすべてのルートを登録できます。<span>|</span>
<コード><span>*/</span>
|とても簡単です。 Laravel に応答する URI を伝えるだけです
<span>//向控制器传递参数,Route::get('/{id}')</span>
<コード>
<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(){})) as的定义路由名
<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>
<p>{<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>
<code><span> <span>'yunshu'<span>,</span></span></span>
<span> <span>'云舒'</span></span>
<code><span> <span>);</span></span>
<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>
<code><span>});</span>
<span>//生成路由URL与跳转</span>
<code><span>Route<span>::<span>get<span>(<span>'test'<span>,<span> <span>function<span>()</span></span></span></span></span></span></span></span></span>
<span>{</span>
<code><span> <span>//生成URL</span></span>
<span> $url <span>=<span> URL<span>::<span>route<span>(<span>'home_route'<span>);</span></span></span></span></span></span></span></span>
<code><span> <span>//echo $url;</span></span>
<span> <span>//跳转</span></span>
<code><span> <span>return<span> <span>Redirect<span>::<span>route<span>(<span>'home_route'<span>);</span></span></span></span></span></span></span></span></span>
<code><span>});</span>
$var <p>=<span data-wiz-span="data-wiz-span"> </span>'def'</p>;<p></p>
<p></p>
<p></p>
<code><span>@include<span>(<span>'layout.header'<span>)</span></span></span></span>
$view
<span><body></span>
View
🎜 $view🎜->🎜var🎜 🎜=🎜 $var🎜;🎜🎜🎜🎜🎜🎜🎜
🎜
🎜🎜 🎜return🎜 $view🎜;🎜🎜🎜🎜
🎜
🎜🎜}));🎜
🎜
🎜🎜//定义制御器🎜
🎜
🎜🎜Route🎜::🎜get🎜(🎜'index'🎜,🎜 🎜関数🎜()🎜🎜🎜🎜🎜🎜🎜🎜🎜
🎜
🎜🎜{🎜
🎜
🎜🎜 $arr 🎜=🎜 array🎜(🎜🎜🎜🎜
🎜)
🎜🎜 🎜'ユンシュ'🎜,🎜🎜🎜
🎜
🎜🎜 🎜'云舒'🎜🎜
🎜
🎜🎜 🎜);🎜🎜
🎜
🎜🎜🎜return🎜view🎜:: 🎜🎜🎜🎜🎜🎜🎜🎜🎜
🎜
🎜🎜});🎜
🎜
🎜🎜// 路由URLと跳转🎜を生成
🎜
🎜🎜Route🎜::🎜get🎜(🎜'test'🎜,🎜 🎜関数🎜()🎜🎜🎜🎜🎜🎜🎜🎜🎜
🎜
🎜🎜{🎜
🎜
🎜🎜 🎜// URL生成🎜🎜
🎜
🎜🎜 $url 🎜=🎜 URL🎜::🎜route🎜(🎜'home_route'🎜);🎜🎜🎜🎜🎜🎜🎜🎜
🎜
🎜🎜 🎜//echo $url;🎜🎜
🎜
🎜🎜 🎜//跳转🎜🎜
🎜
🎜🎜 🎜return🎜 🎜リダイレクト🎜::🎜route🎜(🎜'home_route'🎜);🎜🎜🎜🎜🎜🎜🎜🎜🎜
🎜
🎜🎜});🎜
🎜
🎜
🎜
🎜🎜刃布局🎜🎜
🎜
🎜(master.blade.php):🎜
🎜
🎜
🎜
🎜🎜@include🎜(🎜'layout.header'🎜)🎜🎜🎜🎜
🎜
🎜🎜<body>🎜
🎜<span> <span><div>
<span> <span><div>
<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><div>
<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 プロジェクト、ルーティング、ビュー、ブレード テンプレートの作成) の 1 日目を、関連する内容も含めて紹介しています。PHP チュートリアルに興味のある友人の参考になれば幸いです。