标签: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
标签:style blog http io os ar for sp div
原文地址:http://www.cnblogs.com/dotaeye/p/aspnetmvc_laravel_php_view.html