Blogger Information
Blog 59
fans 6
comment 0
visits 51901
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
控制器创建,视图传值,blade语法:if else ,switch-laraver-56课9.14
希望
Original
1201 people have browsed it

一、控制器创建、视图传值(手动方式)与目录名称一一对应

1、在D:\www\laraver7\resources\views下创建test.blade.php文件

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>测试手动创建</title>
  7. </head>
  8. <body>
  9. <div>用户名为:{{$yhm}}</div>
  10. <div>用户名是:<?php echo e($yhm); ?></div>
  11. <div>用户名:<?php echo e($yhm) ;?></div>
  12. <div>英文名:{!!$name!!}</div>
  13. <div>年龄:<?php echo e($age) ;?></div>
  14. <a href="http://www.php.cn" target="_blank">php中文网</a>
  15. </body>
  16. </html>

2、在D:\www\laraver7\app\Http\Controllers下面创建home.php文件

  1. <?php
  2. namespace App\Http\Controllers;
  3. Class Home extends Controller{
  4. public function index(){
  5. echo 'she is home->index';
  6. }
  7. public function php(){
  8. // return 'this is melind';
  9. $username = '米亚';
  10. $data = ['yhm'=>$username,'name'=>'miya','age'=>20];
  11. $data['yhm'] = $username;
  12. $data['name'] = '<span style="color:red;">miya</span>';
  13. $data['age'] = 18;
  14. return view('test',$data);
  15. // return view('test',['bl'=>$username]);
  16. }
  17. }

3、修改D:\www\laraver7\routes下的web.php文件

  1. <?php
  2. Route::get('/', function () {
  3. return view('test');
  4. });
  5. // 控制器到路由,如何映射刚才写的home.php里的内容?
  6. //要用@符号,指向index()或php()方法
  7. Route::get('/home.html','Home@index');

二、视图中blade语法:if else 、switch、变量的输出方式

  • 修改test.blade.php文件
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>测试手动创建</title>
  7. </head>
  8. <body>
  9. <div>
  10. @if($yhm)
  11. <div>用户名字是:{{$yhm}}</div>
  12. @else
  13. <a href="">登录</a>
  14. @endif
  15. </div>
  16. <div>用户名为:{{$yhm}}</div>
  17. <div>用户名是:<?php echo e($yhm); ?></div>
  18. <div>用户名:<?php echo e($yhm) ;?></div>
  19. <div>英文名:{!!$name!!}</div>
  20. <div>年龄:<?php echo e($age) ;?></div>
  21. <a href="http://www.php.cn" target="_blank">php中文网</a>
  22. <div>
  23. @switch($age)
  24. @case(15)
  25. <div style="color: red;">未成年</div>
  26. @break
  27. @case(18)
  28. <div style="color: green;">成年了</div>
  29. @break
  30. @endswitch
  31. </div>
  32. </body>
  33. </html>


  • 总结:
  • laraver框架控制器创建及传值,blade语法变量的输出方式,都要通过路由D:\www\laraver7\routes下的web.php文件
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:之前咱们学到类似的框架原理, laravel只不过是一个放大版的mvc
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