標籤:style blog http io os ar for sp div
laravel的參考文檔中view的講解有些簡單。
在實際項目開發中view的靈活性其實是非常大。
首先來看看laravel中的布局頁 和asp.net mvc中有什麼不同
<!DOCTYPE html><html><head> <meta charset="UTF-8">
<!--這裡相當於asp.net mvc 中的一個@section(‘title‘,false)-->
@section(‘title‘) <title>{{{$title}}}</title> <!-- using {{$title}} is bad here eg:</title><script>alert(‘hello‘)</script> -->
<!--這裡{{{X}}}與{{}}的區別在與前者會轉碼,後者不轉碼--> @show <meta content=‘width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no‘ name=‘viewport‘> {{ HTML::style(‘vendor/bootstrap/dist/css/bootstrap.css‘) }} @section(‘style‘) @show <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> <!-- WARNING: Respond.js doesn‘t work if you view the page via file:// --> <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script> <![endif]--> </head> <body class="skin-blue"> <!-- 部分視圖 -->
@include(‘shared.header‘) <div class="container "> {{$main}} </div><!-- ./wrapper --> {{ HTML::script(‘vendor/jquery/dist/jquery.js‘) }} {{ HTML::script(‘vendor/bootstrap/dist/js/bootstrap.js‘) }} @section(‘script‘) @show </body> </html>
在看首頁顯示列表的post.home的代碼:
<div class="row"> <div class="col-xs-12 col-sm-6 col-md-8"> {{$content}} </div> <div class="col-xs-6 col-md-4">
<!--這裡這個部分視圖是一個全域都可以引用的,該部分視圖在上一章的route.php的視圖合成器--> @include(‘shared.sidebar‘) </div></div>
還有post.index的代碼 post.index回作為一個子視圖將替換post.home中的{{$content}}
@if(!empty($notFound))<p>Sorry nothing found for your query!</p>@else@foreach($posts as $post)<article class="post"><header class="post-header"><h4 class="post-title">{{link_to_route(‘post.show‘,$post->title,$post->id)}}<div class="pull-right"><span class="text-warning small">{{explode(‘ ‘,$post->created_at)[0]}}</span><span class="small">{{$post->comment_count}} comments </span></div></h4></header><div class="post-content"><p>{{$post->read_more.‘ ...‘}}</p><div >{{link_to_route(‘post.show‘,‘Read full article‘,$post->id)}}</div></div><footer class="post-footer"><hr></footer></article>@endforeach{{$posts->links()}}//這裡顯示分頁。@endif
laravel架構視圖這部分有很多其他組件,本章代碼是沒有引用其他組件的寫法。
簡單的demo是完成了,以下是完整代碼。
http://pan.baidu.com/s/1ntzDsyH
接下來會研究一些laravel中常用到的組件,並應用到demo項目中。
.net轉php laraval架構學習系列(四) 項目實戰---View