一、控制器创建、视图传值(手动方式)与目录名称一一对应
1、在D:\www\laraver7\resources\views下创建test.blade.php文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>测试手动创建</title>
</head>
<body>
<div>用户名为:{{$yhm}}</div>
<div>用户名是:<?php echo e($yhm); ?></div>
<div>用户名:<?php echo e($yhm) ;?></div>
<div>英文名:{!!$name!!}</div>
<div>年龄:<?php echo e($age) ;?></div>
<a href="http://www.php.cn" target="_blank">php中文网</a>
</body>
</html>
2、在D:\www\laraver7\app\Http\Controllers下面创建home.php文件
<?php
namespace App\Http\Controllers;
Class Home extends Controller{
public function index(){
echo 'she is home->index';
}
public function php(){
// return 'this is melind';
$username = '米亚';
$data = ['yhm'=>$username,'name'=>'miya','age'=>20];
$data['yhm'] = $username;
$data['name'] = '<span style="color:red;">miya</span>';
$data['age'] = 18;
return view('test',$data);
// return view('test',['bl'=>$username]);
}
}
3、修改D:\www\laraver7\routes下的web.php文件
<?php
Route::get('/', function () {
return view('test');
});
// 控制器到路由,如何映射刚才写的home.php里的内容?
//要用@符号,指向index()或php()方法
Route::get('/home.html','Home@index');
二、视图中blade语法:if else 、switch、变量的输出方式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>测试手动创建</title>
</head>
<body>
<div>
@if($yhm)
<div>用户名字是:{{$yhm}}</div>
@else
<a href="">登录</a>
@endif
</div>
<div>用户名为:{{$yhm}}</div>
<div>用户名是:<?php echo e($yhm); ?></div>
<div>用户名:<?php echo e($yhm) ;?></div>
<div>英文名:{!!$name!!}</div>
<div>年龄:<?php echo e($age) ;?></div>
<a href="http://www.php.cn" target="_blank">php中文网</a>
<div>
@switch($age)
@case(15)
<div style="color: red;">未成年</div>
@break
@case(18)
<div style="color: green;">成年了</div>
@break
@endswitch
</div>
</body>
</html>
- 总结:
- laraver框架控制器创建及传值,blade语法变量的输出方式,都要通过路由D:\www\laraver7\routes下的web.php文件