Laravel 模板基础语法 流程控制 模板中的URL

2017-05-16  本文已影响0人  捔落纏綿

模板的基础语法 和include 引用

@section('content')
   content
    <!--1. 模板中输出php变量-->
    {{$name}}

    <!--2.模板中调用php代码-->
    {{date('Y-m-d H:i:s',time())}}
    {{in_array($name,$arr)?'true':'false'}}
    {{$name3 or 'default'}}

    <!--3.原样输出-->
    @{{$name}}

    {{--4.模板注释--}}

    {{--5.引入模板子视图--}}
    @include('student.common',['message'=>'我是错误信息'])
@stop

流程控制

 {{--if语句--}}
    @if($name == 'qwe')
        I'm sean
    @elseif($name=='qwer')
        I'm qwer
    @else
        who am I?
    @endif

    @if(in_array($name,$arr))
        true
    @else
        false
    @endif


    {{-- unless  if 的取反--}}
    @unless($name=='qwe')
        我不是qwe
    @endunless

   {{--for 循环--}}
    @for($i=0;$i<10;$i++)
        {{$i }}
    @endfor

   {{--foreach 输出--}}
    @foreach($students as $student)
        {{$student->name }}
    @endforeach

   {{--forelse 判断数组是否为空 不为空循环输出  为空提示--}}
    @forelse($students as $student)
        {{$student->name }}
    @empty
        null
    @endforelse

模板中的url

   <a href="{{url('student/urlTest')}}">url()路由</a>
    <a href="{{route('url')}}">route()别名</a>
    <a href="{{action('StudentsController@urlTest')}}">action()控制器方法</a>
上一篇 下一篇

猜你喜欢

热点阅读