例如现在是home应用

在app/home/model中新建文件 User.php文件


<?php
namespace app\home\model;
use think\Model;
class Userextends Model
{
  public function test()
  {
    $where = [
      [‘id’,'<‘,5],
    ];
    $admin = self::where($where)->find()->toArray();
    return $admin;
  }
}

这样对用的数据库表即为 user,如果在config/database.php文件中配置了prefix表前缀”tp_”那么对应的就是表 tp_user

使用指定的表与库


// 设置当前模型对应的完整数据表名称
    protected $table = 'think_user';
    
    // 设置当前模型的数据库连接
    protected $connection = 'db_config';

在控制器中使用


   protected function initialize()
    {
        $this->model = new \app\home\model\Content;
    }
   public function catalog()
    {
        halt($this->model->test());
    }

 

说点什么
支持Markdown语法
好耶,沙发还空着ヾ(≧▽≦*)o
Loading...