app>index>controller>index.php
<?php
namespace app\index\controller;
use app\BaseController;
//! 2、引入Db门面类
use think\facade\Db;
//! 15、引入Request门面类
use think\facade\Request;
use think\facade\Config;
use app\model\OykUser;
use app\model\User;
// 引入视图门面类
use think\facade\View;
public function three(){
//! 4.助手函数
// 门面类 获取get传值
print_r(Request::get());
//tp函数,也可以获取get传值
input('get.');
print_r(input('get.'));
print_r(config());
// 5.注意:门面类,普通类,助手函数,它们有一些功能1是重复的
$user = Db::table('oyk_user')->select();
dump($user);
// 6.多应用
// http://www.ou.com/index.php/index/index/three?id=111
// 单应用
// http://www.ou.com/index.php/index/three?id=111
}
public function for(){
echo 111 ;
// 视图门面类,fetch方法,传值可以不传
// fetch()参数是:页面的地址
// mvc,v放在项目目录里,index目录
// php文件名(class),代表v的目录
// php方法名 对应v的目录下的index目录下的for文件
//! (app里的)index文件夹->(controller里的)index.php->for函数
//! (for里的)View::fetch要与上述一一对应
//! (app里的)index文件夹->(View里的)index文件->for文件
return View::fetch();
$user = Db::table('oyk_user')->where('status',1)->select();
foreach($user as $v){
echo $v['nickname'] . '<br>';
}
// 在c里面获取的数据,要传给v,才能在页面中进行设置,进行循环
// 在c里只返回数据,样式在v里写,m里写对数据库表的操作
View::assign('user',$user);
return View::fetch();
}
app>index>View>index>for.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<div style="color: red">欧阳克</div>
<div style="color: green">
<!-- 视图页面循环写法 -->
{foreach $user as $v}
<li>{$v['nickname']} - {$v['phone']} - {$v['last_time']|date='Y-m-d H:i:s'}</li>
{/foreach}
</div>
</body>
</html>