04-模型与杂项

该代码示例展示了在thinkPHP框架中如何使用门面类如Db,Request,Config以及助手函数进行GET参数获取、数据库查询和视图渲染。在three函数中,演示了Db门面查询数据并使用助手函数input获取GET参数。在for函数中,展示视图渲染过程,使用View门面fetch方法加载模板,并传递数据到视图进行循环显示。
摘要由CSDN通过智能技术生成

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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

七色的天空

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值