Correcting teacher:天蓬老师
Correction status:qualified
Teacher's comments:blade模板 也smarty之间有不少相似之处, 但更加的简洁
1、显示数据
//给视图传参
Route::get('/', function () {
return view('welcome',['name' => 'eric']);
});
//视图内接受参数并显示
hello, {{ $name }} //结果:hello, eric
2、循环、流程控制
@foreach($articles as $article)
文章标题为:{{ $article['title'] }}
@endforeach
@for($i=0; $i<10; $i++)
{{$i}}
@endfor
@forelse($articles as $article)
{{ @$article['title'] }}
@empty
<h2> no results</h2>
@endforelse
@while (true)
<p>I'm looping forever.</p>
@endwhile
@if (count($records) === 1)
有一条记录
@elseif (count($records) > 1)
有多条记录
@else
记录为空
@endif
1、原生操作
//查询
$res = DB::select('select * from article where id=?',[2]);
//输出:
Array
(
[0] => stdClass Object
(
[art_id] => 2
[title] => CBA体育
[content] => 易建联荣获第七周最有价值球员称号
[create_dt] =>
)
)
//新增
$res = DB::insert('insert into article (title,content) values (?,?)',['标题','内容']);
//输出:
1
//更新
$res = DB::update('update article set title = ? where id=?', ['新标题',2]);
//输出:
1
//删除
$res = DB::delete('delete from article where id=?',[2]);
//输出:
1
THE END !