ホームページ > バックエンド開発 > PHPチュートリアル > Laravel 学習の初日 (laravel プロジェクト、ルーティング、ビュー、ブレード テンプレートの作成)、laravelblade_PHP チュートリアル

Laravel 学習の初日 (laravel プロジェクト、ルーティング、ビュー、ブレード テンプレートの作成)、laravelblade_PHP チュートリアル

WBOY
リリース: 2016-07-13 10:06:44
オリジナル
1022 人が閲覧しました

Laravel学習初日(laravelプロジェクト、ルーティング、ビュー、ブレードテンプレートの作成)、laravelblade

laravelプロジェクトの作成

composer create-project laravel/laravel learnlv 4.1.* ヘルプを表示:composer create-project ​ 職人の道具を使う その他のコマンドについては、http://blog.luoyunshu.com/laravel-cheatsheet を参照してください。 ​

ルーティング

ルート.php: <span class="pun"><?<span class="pln">php</span></span><span class="com">/*</span>php<span class="com">|--------------------------------------------------------------------------</span><span class="com">| Application Routes</span><span class="com">|--------------------------------------------------------------------------</span>/*<span class="com">|</span> <span class="com">| Here is where you can register all of the routes for an application.</span>|----------------------------------------------------- ----------------------------------<span class="com">| It's a breeze. Simply tell Laravel the URIs it should respond to</span> <span class="com">| and give it the Closure to execute when that URI is requested.</span>| 申請ルート<span class="com">|</span> <span class="com">*/</span>|----------------------------------------------------- ----------------------------------<span class="com">//向控制器传递参数,Route::get('/{id}')</span> <span class="com">//两种格式:1、Route::get('/', function(){})</span>|<span class="com">// 2、Route::get('/', array('as'=>'home_route',function(){})) as的定义路由名称</span> <span class="typ">Route<span class="pun">::<span class="kwd">get<span class="pun">(<span class="str">'/'<span class="pun">,<span class="pln"> array<span class="pun">(<span class="str">'as'<span class="pun">=><span class="str">'home_route'<span class="pun">,<span class="pln"> <span class="kwd">function<span class="pun">()</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>| ここで、アプリケーションのすべてのルートを登録できます。<span class="pun">{</span> <span class="pln"> <span class="com">//向视图传递参数</span></span>| 応答する URI を Laravel に伝えるだけです<span class="pln"> <span class="com">//方法一:</span></span> <span class="pln"> <span class="com">//$var = 'hello world';</span></span>| その URI が要求されたときに実行するクロージャを指定します。<span class="pln"> <span class="com">//return View::make('hello')->with('var', $var);</span></span> <span class="pln"> <span class="com">//方法二</span></span>|<span class="pln"> <span class="com">//$var = 'abcd';</span></span> <span class="pln"> <span class="com">//return View::make('hello', array('var'=>$var));</span></span>*/<span class="pln"> <span class="com">//方法三</span></span><span class="pln"> $var <span class="pun">=<span class="pln"> <span class="str">'def'<span class="pun">;</span></span></span></span></span>//パラメータをコントローラーに渡します、Route::get('/{id}')<span class="pln"> $view <span class="pun">=<span class="pln"> <span class="typ">View<span class="pun">::<span class="pln">make<span class="pun">(<span class="str">'index.hello'<span class="pun">);</span></span></span></span></span></span></span></span></span> <span class="pln"> $view<span class="pun">-><span class="kwd">var<span class="pln"> <span class="pun">=<span class="pln"> $var<span class="pun">;</span></span></span></span></span></span></span>//2 つの形式: 1. Route::get('/', function(){})<span class="pln"> <span class="kwd">return<span class="pln"> $view<span class="pun">;</span></span></span></span> <span class="com">// 2. Route::get('/', array('as'=>'home_route',function(){})) を定義されたルート名として使用します<span class="pun"></span></span> 🎜ルート🎜::get🎜('/'🎜, array🎜('as'🎜=>'home_route'🎜, function🎜()🎜🎜🎜🎜 🎜🎜🎜🎜🎜🎜🎜🎜🎜🎜🎜 🎜🎜{🎜 🎜 //ビューにパラメータを渡します🎜🎜 🎜 //方法 1: 🎜🎜 🎜 //$var = 'hello world';🎜🎜 🎜 //return View::make('hello')->with('var', $var);🎜🎜 ​ 🎜 //方法 2🎜🎜 🎜 //$var = 'abcd';🎜🎜 🎜 //return View::make('hello', array('var'=>$var));🎜🎜 ​ 🎜 //方法 3🎜🎜 🎜 $var 🎜= 'def'🎜;🎜🎜🎜🎜🎜 🎜 $view 🎜= View🎜::make🎜('index.hello'🎜);🎜🎜🎜🎜🎜🎜🎜🎜🎜 🎜 $view🎜->var 🎜= $var🎜;🎜🎜🎜🎜 🎜🎜🎜 🎜 return $view🎜;🎜🎜🎜🎜 🎜🎜}));<span class="com">//定义控制器</span>//コントローラーを定義します<span class="typ">Route<span class="pun">::<span class="kwd">get<span class="pun">(<span class="str">'index'<span class="pun">,<span class="pln"> <span class="kwd">function<span class="pun">()</span></span></span></span></span></span></span></span></span><span class="pun">{</span> <span class="pln"> $arr <span class="pun">=<span class="pln"> array<span class="pun">(</span></span></span></span>ルート<span class="pln"> <span class="str">'yunshu'<span class="pun">,</span></span></span>::get<span class="pln"> <span class="str">'云舒'</span></span>('index'<span class="pln"> <span class="pun">);</span></span>,<span class="pln"> <span class="kwd">return<span class="pln"> <span class="typ">View<span class="pun">::<span class="pln">make<span class="pun">(<span class="str">'index.index'<span class="pun">,<span class="pln"> array<span class="pun">(<span class="str">'arr'<span class="pun">=><span class="pln">$arr<span class="pun">));</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span> function<span class="pun">});</span>() <span class="com">//生成路由URL与跳转</span><span class="typ">Route<span class="pun">::<span class="kwd">get<span class="pun">(<span class="str">'test'<span class="pun">,<span class="pln"> <span class="kwd">function<span class="pun">()</span></span></span></span></span></span></span></span></span><span class="pun">{</span><span class="pln"> <span class="com">//生成URL</span></span><span class="pln"> $url <span class="pun">=<span class="pln"> URL<span class="pun">::<span class="pln">route<span class="pun">(<span class="str">'home_route'<span class="pun">);</span></span></span></span></span></span></span></span><span class="pln"> <span class="com">//echo $url;</span></span><span class="pln"> <span class="com">//跳转</span></span><span class="pln"> <span class="kwd">return<span class="pln"> <span class="typ">Redirect<span class="pun">::<span class="pln">route<span class="pun">(<span class="str">'home_route'<span class="pun">);</span></span></span></span></span></span></span></span></span><span class="pun">});</span>

{

<span class="lit">@include<span class="pun">(<span class="str">'layout.header'<span class="pun">)</span></span></span></span> <span class="str"><body></span><span class="pln"> <span class="str"><div></span></span> $arr <span class="pln"> <span class="str"><div></span></span>=<span class="pln"> <span class="lit">@yield<span class="pun">(<span class="str">'content'<span class="pun">)</span></span></span></span></span> array<span class="pln"> <span class="pun"></<span class="pln">div<span class="pun">></span></span>
(<span class="pln"> <span class="pun"></<span class="pln">div<span class="pun">></span></span>
<span class="pln"> <span class="str"><div></span></span><span class="pln"> <span class="str"><div></span></span><span class="pln"> <span class="lit">@section<span class="pun">(<span class="str">'section'<span class="pun">)</span></span></span></span></span><span class="pln"> <span class="pun">哈哈</span></span> <span class="pln"> <span class="lit">@show</span></span><span class="pln"> <span class="pun"></<span class="pln">div<span class="pun">></span></span>
「ユンシュ」<span class="pln"> <span class="pun"></<span class="pln">div<span class="pun">></span></span>
<span class="pln"><span class="pun"><span class="pln"> <span class="pun">🎜<span class="str">「ユンシュ」🎜🎜🎜 🎜🎜 🎜);🎜🎜🎜 🎜🎜 <span class="kwd">return🎜 <span class="typ">View🎜::🎜make🎜(<span class="str">'index.index'🎜,🎜 array🎜(<span class="typ"> ="str">'arr'🎜=> 🎜🎜});🎜🎜 ​ 🎜<span class="com">//ルーティング URL を生成してジャンプします🎜🎜 🎜<span class="typ">ルート🎜::<span class="kwd">get🎜(<span class="str">'test'🎜,🎜 <span class="kwd">function🎜() 🎜🎜🎜🎜🎜🎜🎜🎜🎜🎜 🎜🎜{🎜🎜 🎜🎜 <span class="com">//URL を生成します🎜🎜🎜 🎜🎜 $url 🎜=🎜 URL🎜::🎜route🎜(<span class="str">'home_route'🎜);🎜🎜🎜🎜🎜🎜🎜🎜🎜 🎜🎜 <span class="com">//echo $url;🎜🎜🎜 ​ 🎜🎜 <span class="com">//ジャンプ🎜🎜🎜 🎜🎜<span class="kwd">return🎜<span class="typ">リダイレクト🎜::🎜route🎜(<span class="str">'home_route'🎜);🎜🎜🎜🎜🎜🎜🎜🎜 🎜🎜 🎜🎜});🎜🎜 🎜🎜ブレードレイアウト🎜🎜 (マスター.ブレード.php): 🎜<span class="lit">@include🎜(<span class="str">'layout.header'🎜)🎜🎜🎜🎜🎜 🎜<span class="str"><ボディ>🎜🎜 🎜🎜 <span class="str"><div>🎜🎜🎜 🎜🎜 <span class="str"><div>🎜🎜🎜 🎜🎜 <span class="lit">@yield🎜(<span class="str">'コンテンツ'🎜)🎜🎜🎜🎜🎜🎜 🎜🎜 🎜</🎜div🎜>🎜🎜🎜🎜🎜 🎜🎜 🎜</🎜div🎜>🎜🎜🎜🎜🎜 ​ 🎜🎜 <span class="str"><div>🎜🎜🎜 🎜🎜 <span class="str"><div>🎜🎜🎜 🎜🎜<span class="lit">@section🎜(<span class="str">'section'🎜)🎜🎜🎜🎜🎜🎜 🎜🎜🎜はは🎜🎜🎜 🎜🎜<span class="lit">@show🎜🎜🎜 🎜🎜 🎜</🎜div🎜>🎜🎜🎜🎜🎜 🎜🎜 🎜</🎜div🎜>🎜🎜🎜🎜🎜 🎜🎜 🎜{{--🎜 🎜コメントコード--}}</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></span></span></span></span> <span class="lit">@include<span class="pun">(<span class="str">'layout.footer'<span class="pun"> )<code class="language-php"><span class="lit">@include<span class="pun">(<span class="str">'layout.footer'<span class="pun">)</span></span></span></span><span class="lit">@extends<span class="pun">(<span class="str">'layout.master'<span class="pun">)</span></span></span></span><span class="pun">{{--<span class="pln"> <span class="pun">使用<span class="pln">master<span class="pun">模板<span class="pln"> <span class="pun">--}}</span></span></span></span></span></span></span><span class="pun">{{--<span class="pln"> <span class="pun">使用这部分内容填充模板<span class="pln"> <span class="pun">--}}</span></span></span></span></span><span class="lit">@section<span class="pun">(<span class="str">'content'<span class="pun">)</span></span></span></span> インデックス.ブレード.php: <span class="lit">@extends<span class="pun">(<span class="str">'layout.master'<span class="pun"> )<code class="language-php"><span class="pln"> <span class="lit">@foreach<span class="pun">(<span class="pln">$arr <span class="kwd">as<span class="pln"> $a<span class="pun">)</span></span></span></span></span></span></span><span class="pln"> <span class="pun">{{<span class="pln"> $a <span class="pun">}}</span></span></span></span><span class="pln"> <span class="lit">@endforeach</span></span><span class="pln"> <span class="pun">{{--<span class="pln"> <span class="pun">创建图片<span class="pln"> <span class="pun">--}}</span></span></span></span></span></span><span class="pln"> <span class="pun">{{<span class="pln"> HTML<span class="pun">::<span class="pln">image<span class="pun">(<span class="str">'image/1.jpg'<span class="pun">)<span class="pln"> <span class="pun">}}</span></span></span></span></span></span></span></span></span></span> <span class="pun">{{--<span class="pln"> <span class="pun">使用<span class="pln">マスター<span class="pun">型板<span class="pln"> <span class="pun">--}}<code class="language-php"><span class="lit">@stop</span><span class="pun">{{--<span class="pln"> <span class="pun">覆盖或者重写父模板内容<span class="pln"> <span class="pun">--}}</span></span></span></span></span><span class="lit">@section<span class="pun">(<span class="str">'section'<span class="pun">)</span></span></span></span><span class="pln"> <span class="pun">{{--<span class="pln"> <span class="pun">拿到父模板的内容使用<span class="lit">@parent<span class="pln"> <span class="pun">--}}</span></span></span></span></span></span></span><span class="pln"> <span class="lit">@parent</span></span><span class="pln"> <span class="str">'你好呀'</span></span><span class="lit">@stop</span>   <span class="pun">{{--<span class="pln"> <span class="pun">この部分のコンテンツ充填モジュールを使用します<span class="pln "> <span class="pun">--}}<span data-wiz-span="data-wiz-span"></span></span><p align="left"></p> <div style="display:none;"> <code class=" language-php"><span class="lit">@section<span class="pun">(<span class="str">'content'<span class="pun">)<span id="url" itemprop="url"> </span><span id="indexUrl" itemprop="indexUrl"></span><span id="isOriginal" itemprop="isOriginal"> <code class=" language-php"><span class="pln"> <span class="lit">@foreach<span class="pun">(<span class="pln">$arr <span class="kwd">as<span class="pln"> $a<span class="pun">)</span><span id="isBasedOnUrl" itemprop="isBasedOnUrl"></span><span id="genre" itemprop="genre"></span><span id="description" itemprop="description"></span></span></span></span></span></span></span>
<span class="pln"> <span class="pun">{{<span class="pln"> $a <span class="pun">}} <div class="art_confoot"></div>🎜 <code class=" language-php"><span class="pln"> <span class="lit">@endforeach🎜🎜🎜   <code class=" language-php"><span class="pln"> <span class="pun">{{--<span class="pln"> <span class="pun">创建图片<span class="pln"> <span class="pun">--}}🎜🎜🎜🎜🎜🎜🎜 <code class=" language-php"><span class="pln"> <span class="pun">{{<span class="pln"> HTML<span class="pun">::<span class="pln">image<span class="pun">(<span class="str">'image/1.jpg'<span class="pun">)<span class="pln"> <span>}}🎜🎜🎜🎜🎜🎜🎜🎜🎜🎜🎜 <code class=" language-php"><span class="lit">@stop🎜🎜   <code class=" language-php"><span class="pun">{{--<span class="pln"> <span class="pun">覆盖または重写父模板内容<span class=" pln"> <span class="pun">--}}🎜🎜🎜🎜🎜🎜 <code class=" language-php"><span class="lit">@section<span class="pun">(<span class="str">'section'<span class="pun">)🎜 🎜🎜🎜🎜 <code class=" language-php"><span class="pln"> <span class="pun">{{--<span class="pln"> <span class="pun">拿到父模板内容の使用<span class="lit">@parent<span class="pln"> <span class="pun">--}}🎜🎜🎜🎜🎜🎜🎜🎜 <code class=" language-php"><span class="pln"> <span class="lit">@parent🎜🎜🎜 <code class=" language-php"><span class="pln"> <span class="str">'你好呀'🎜🎜🎜 <code class=" language-php"><span class="lit">@stop🎜🎜   🎜🎜代打打包:🎜🎜 http://files.cnblogs.com/files/luoyunshu/learnlv.zip🎜 🎜🎜🎜http://www.bkjia.com/PHPjc/957480.html🎜🎜www.bkjia.com🎜🎜tru​​e🎜🎜http://www.bkjia.com/PHPjc/957480.html🎜🎜技術記事🎜🎜 Laravel学习第一天(创建laravel项目、路由、視图、ブレード模板)、laravelblade创建laravel项目composer create-project laravel/laravel learnlv 4.1.* 查看帮助:...🎜🎜🎜🎜 🎜🎜</span>
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のおすすめ
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート