Blogger Information
Blog 16
fans 7
comment 1
visits 11483
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
12月30日- Blade模板引擎与数据操作
Eric
Original
885 people have browsed it

一、Blade模板

1、显示数据

  1. //给视图传参
  2. Route::get('/', function () {
  3. return view('welcome',['name' => 'eric']);
  4. });
  5. //视图内接受参数并显示
  6. hello, {{ $name }} //结果:hello, eric

2、循环、流程控制

@foreach

  1. @foreach($articles as $article)
  2. 文章标题为:{{ $article['title'] }}
  3. @endforeach

@for

  1. @for($i=0; $i<10; $i++)
  2. {{$i}}
  3. @endfor

@forelse

  1. @forelse($articles as $article)
  2. {{ @$article['title'] }}
  3. @empty
  4. <h2> no results</h2>
  5. @endforelse

@while...@endwhile

  1. @while (true)
  2. <p>I'm looping forever.</p>
  3. @endwhile

@if...@endif

  1. @if (count($records) === 1)
  2. 有一条记录
  3. @elseif (count($records) > 1)
  4. 有多条记录
  5. @else
  6. 记录为空
  7. @endif

二、数据操作

1、原生操作

  1. //查询
  2. $res = DB::select('select * from article where id=?',[2]);
  3. //输出:
  4. Array
  5. (
  6. [0] => stdClass Object
  7. (
  8. [art_id] => 2
  9. [title] => CBA体育
  10. [content] => 易建联荣获第七周最有价值球员称号
  11. [create_dt] =>
  12. )
  13. )
  14. //新增
  15. $res = DB::insert('insert into article (title,content) values (?,?)',['标题','内容']);
  16. //输出:
  17. 1
  18. //更新
  19. $res = DB::update('update article set title = ? where id=?', ['新标题',2]);
  20. //输出:
  21. 1
  22. //删除
  23. $res = DB::delete('delete from article where id=?',[2]);
  24. //输出:
  25. 1

THE END !

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:blade模板 也smarty之间有不少相似之处, 但更加的简洁
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!