Blogger Information
Blog 28
fans 0
comment 0
visits 19712
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1104 @include header文件及渲染控制器中的数据到视图中 20191104 2000-2200
没有人的夏天的博客
Original
763 people have browsed it

larvael 控制器数据的视图渲染

控制器 增加数组数据

多维数据放到不同的数组中,并综合到一个数据中进行数据带入

  1. public function infoarr()
  2. {
  3. $con_data = [
  4. ['cid' => 1, 'cont' => '中国电影'],
  5. ['cid' => 2, 'cont' => '外国电影']
  6. ];
  7. $mov_data = [
  8. ['mid' => 1, 'mov_name' => "倚天屠龙记", 'cid' => 1, 'img' => "1.jpg", 'title' => "元朝末年,群雄纷起,武林动荡。"],
  9. ['mid' => 2, 'mov_name' => "都挺好", 'cid' => 1, 'img' => "2.jpg", 'title' => "苏母的的突然离世打破了这个家庭外表的平静。"],
  10. ['mid' => 3, 'mov_name' => "如果可以这样爱", 'cid' => 1, 'img' => "3.jpg", 'title' => "一对已婚男女突然徇情自杀,以为可以结束这一切,"],
  11. ['mid' => 3, 'mov_name' => "如果可以这样爱", 'cid' => 1, 'img' => "3.jpg", 'title' => "一对已婚男女突然徇情自杀,以为可以结束这一切,"]
  12. ];
  13. $dir_data = [
  14. ['did' => 1, 'mid' => 1, 'd_name' => "李安", 'd_cont' => "中国"],
  15. ['did' => 2, 'mid' => 2, 'd_name' => "吴宇森", 'd_cont' => "美国"],
  16. ['did' => 3, 'mid' => 3, 'd_name' => "冯小刚", 'd_cont' => "中国"]
  17. ];
  18. return view('lvio\index', [
  19. 'mov_data' => $mov_data,
  20. 'dir_data' => $dir_data,
  21. 'con_data' => $con_data
  22. ]);
  23. }

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 的注释语句

  1. {{ ---infolist-- }}
  2. <div>
  3. @foreach ($mov_data as $mv)
  4. <div>
  5. <img src="\img\{{ $mv['img'] }}" alt="...">
  6. <div>
  7. <h5>{{ $mv['mov_name'] }}</h5>
  8. <h6>
  9. @foreach ($dir_data as $dv)
  10. @if ($dv['mid']==$mv['mid'])
  11. {{ $dv['d_name'].' 作品' }}
  12. @endif
  13. @endforeach
  14. @foreach ($con_data as $cv)
  15. @if ($cv['cid']==$mv['cid'])
  16. {{ ' '.$cv['cont']}}
  17. @endif
  18. @endforeach
  19. </h6>
  20. <p>{{ $mv['title'] }}</p>
  21. <a>了解更多</a>
  22. </div>
  23. </div>
  24. @endforeach
  25. </div>

@include header.php文件

include 文件目录:resources\views
include 时可以指定下级目录
include 文件内的变量由 文件带入

主体文件:

  1. <body>
  2. @include('lvio\header')

header文件:resources\views\lvio\header.blade.php

  1. {{--hearder--}}
  2. <div>
  3. <h5>电影列表</h5>
  4. <nav>
  5. @foreach ($con_data as $v)
  6. <a href="#">{{ $v['cont'] }}</a>
  7. @endforeach
  8. </nav>
  9. </div>

效果图

inculde 效果图

Correction status:qualified

Teacher's comments:标签用得不错
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