larvael 控制器数据的视图渲染
控制器 增加数组数据
多维数据放到不同的数组中,并综合到一个数据中进行数据带入
public function infoarr()
{
$con_data = [
['cid' => 1, 'cont' => '中国电影'],
['cid' => 2, 'cont' => '外国电影']
];
$mov_data = [
['mid' => 1, 'mov_name' => "倚天屠龙记", 'cid' => 1, 'img' => "1.jpg", 'title' => "元朝末年,群雄纷起,武林动荡。"],
['mid' => 2, 'mov_name' => "都挺好", 'cid' => 1, 'img' => "2.jpg", 'title' => "苏母的的突然离世打破了这个家庭外表的平静。"],
['mid' => 3, 'mov_name' => "如果可以这样爱", 'cid' => 1, 'img' => "3.jpg", 'title' => "一对已婚男女突然徇情自杀,以为可以结束这一切,"],
['mid' => 3, 'mov_name' => "如果可以这样爱", 'cid' => 1, 'img' => "3.jpg", 'title' => "一对已婚男女突然徇情自杀,以为可以结束这一切,"]
];
$dir_data = [
['did' => 1, 'mid' => 1, 'd_name' => "李安", 'd_cont' => "中国"],
['did' => 2, 'mid' => 2, 'd_name' => "吴宇森", 'd_cont' => "美国"],
['did' => 3, 'mid' => 3, 'd_name' => "冯小刚", 'd_cont' => "中国"]
];
return view('lvio\index', [
'mov_data' => $mov_data,
'dir_data' => $dir_data,
'con_data' => $con_data
]);
}
blade.php 模版视图输出
1- @foreach ($mov_data as $mv) @endforeach
是laravel 的循环语句
2- @if ($dv['mid']==$mv['mid']) @endif
是 laravel 的判断语句
3- {{ $mv['mov_name'] }}
是 larvael 的输出语句
4- {{ --infolist-- }}
是 larvael 的注释语句
{{ ---infolist-- }}
<div>
@foreach ($mov_data as $mv)
<div>
<img src="\img\{{ $mv['img'] }}" alt="...">
<div>
<h5>{{ $mv['mov_name'] }}</h5>
<h6>
@foreach ($dir_data as $dv)
@if ($dv['mid']==$mv['mid'])
{{ $dv['d_name'].' 作品' }}
@endif
@endforeach
@foreach ($con_data as $cv)
@if ($cv['cid']==$mv['cid'])
{{ ' '.$cv['cont']}}
@endif
@endforeach
</h6>
<p>{{ $mv['title'] }}</p>
<a>了解更多</a>
</div>
</div>
@endforeach
</div>
@include header.php文件
include 文件目录:resources\views
include 时可以指定下级目录
include 文件内的变量由 文件带入
主体文件:
<body>
@include('lvio\header')
header文件:resources\views\lvio\header.blade.php
{{--hearder--}}
<div>
<h5>电影列表</h5>
<nav>
@foreach ($con_data as $v)
<a href="#">{{ $v['cont'] }}</a>
@endforeach
</nav>
</div>
效果图