laravel入门之blade模板

jianfly.com 2019-01-31 1382次浏览

<?php
//layouts.blade.php
@yield('title')
@section('header') 
@show
@yield('content','主要内容区域')
//继承
@extends('layouts')
//重写
@section('header')
	@parent //父模板里面的内容,这是与yield区别
	。。。。。//内容
@stop
//重写yield指定
@section('content')
	。。。。。//内容
@stop

//基本语法
//1.输出php变量
{{$name}}
//2.调用php代码
{{time()}}
{{ date('Y-m-d H:i:s', time()) }}
{{ var_dump($arr) }}
{{ isset($name) ? $name : 'default' }} 等同于 {{ $name or 'default' }}
//3.原样输出
@{{ $name }}  不解析
//4.模板中的注释
{{-- 这里是注释,看不到 --}}
//5.引入子视图include
@include('student.commen1', ['message' => "在这里传值"])

//流程控制
@if ($name == 'sean')
	I am sean
@elseif ($name == 'imooc')
	I am imooc
@else
	Who am I?
@endif

@unless( $name == 'sean' )
	I am not sean
@endunless

@for ($i=0; $i<10; $i++)
	<p>{{ $i }}</p>
@endfor

@foreach ( $student as $student )
	<li>{{$student->name}}</li>
@endforeach

@forelse ( $student as $student )
	<p>{{$student->name}}</p>
@empty
	<p>null</p>
@endforelse

//模板中的url
<a href="{{url('url')}}">url()</a><!--get获取的值-->
<a href="{{ action('StudentController@urlTest') }}">action()</a>
<a href="{{ route('url') }}">route()</a><!--别名-->
Route::get('articles', ['uses'=>'ArticlesController@index', 'as'=>'articles.index']);
'articles'                   ------   url
'ArticlesController@index'   ------   action
'articles.index'             ------   route