創建laravel專案
composer create-project laravel/laravel learnlv 4.1.*
查看幫助:composer create-project
使用artisan工具
產生key:php artisan key:genrate,更多指令見:http://blog.luoyunshu.com/laravel-cheatsheet
路由
route.php:
<span><span>php</span></span>
<span>/*</span>
<span>|---------------------------------------------- ----------------------------</span>
<span>| Application Routes</span>
<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>
<span>| and give it the Closure to execute when that URI is requested.</span>
<span>|</span>
<span>*/</span>
<span>//向控制器傳遞參數,Route::get('/{id}')</span>
<span>//兩種格式:1、Route::get('/', function(){})</span>
<span>// 2、Route::get('/', array('as'=>'home_route',function(){})) as的定義路由名稱</span>
<span>Route<span>::<span>get<span>(<span>'/'<span>,<span> array<span>(<span>'as'<span>=><span>'home_route'<span>,,'as'<span>=><span>'home_route' <span></span></span></span></span> </span></span></span></span></span></span></span>
</span></span></span>{</span>
<span> </span>//向視圖傳遞參數
<span><span></span> </span>//方法一:
<span><span></span> </span>//$var = 'hello world';
<span><span></span> </span>//return View::make('hello')->with('var', $var);
<span><span></span> </span>//方法二
<span><span></span> </span>//$var = 'abcd';
<span><span></span> </span>//return View::make('hello', array('var'=>$var));
<span><span></span> </span>//方法三
<span><span></span> $var </span>=
;<span><span><span><span><span></span>
</span></span></span> $view </span>=
::make<span>(<span>'index.hello'<span>);<span><span><span><span><span><span>);</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><span></span></span></span></span>
<span>
</span>
return $view<span>;</span>
<span>
<span><span><span>}));<span><span><span>
<span><span></span>//定義控制器</span></span></span>
</span></span></span>Route</span>::</span>get
(
, <span>function</span>()
<span><span>()<span><span></span></span>
</span></span>
{
<span><span><span> $arr </span>=</span> array</span>(
<span>
</span>
,<span><span></span></span>
'雲舒'<span><span><span><span>
<span><span><span> <span>);<span><span><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></span></span>
<span></span>
<span>});</span>
<span>//生成路由URL與跳轉<span><span><span>
<span><span><span>Route<span>::<span>get</span>(</span>'test'</span>,</span> </span>function</span>()</span></span></span>
()<span></span>
{<span></span>
//生成URL<span><span><span>
<span><span><span> $url <span>=<span> URL</span>::</span>route</span>(</span>'home_route'</span>);</span></span></span>
);<span></span>
);
<span></span>);
//echo $url;
<span></span> //跳轉
Redirect<span>::</span>route
(
});<span></span>
<span>
</span>(master.blade.php):
<span> <span><div>
<p><code><span> <span><div>
<p><code><span> <span>@yield<span>(<span>'content'<span>)</span></span></span></span></span>
<span> <span><span>div<span>></span></span></span></span>
<span> <span><span>div<span>></span></span></span></span>
<span> <span><div>
<p><code><span> <span><div>
<p><code><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> <span><span>div<span>></span></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>
@section('content')<span></span>
@foreach
(
as $a)<span></span>
<span></span>
{{ $a }}<span></span>
@endforeach
{{-- 創建圖片 --}}<span></span>
{{ HTML
::
('image/1.jpg'<span>)</span>
}}
@stop<span></span>
{{--
--}}<span></span>
('section')<span>
</span> {{-- 拿到父親模板的內容使用@parent
<span></span>
<span></span>
@parent<span></span>
@stop
🎜 🎜🎜🎜程式碼打包:🎜🎜🎜 🎜http://files.cnblogs.com/files/luoyunshu/learnlv.zip🎜 🎜 以上就介紹了Laravel學習第一天(創建laravel專案、路由、視圖、blade模板),包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。 🎜 🎜 🎜