默认使用$this表示本表(模型),如果需要用Db::name()请导入该模块:
use think\facade\Db;
<?php
namespace app\portal\model;
use think\facade\Db;
use think\Model;
class CopTopicsModel extends Model
{
/**
* 模型名称
* @var string
*/
protected $name = 'cop_topics';
protected $autoWriteTimestamp=true;
public function adminGetTopics($id){
$where[]=["a.id",'=',$id];
return Db::name('cop_topics')->alias('a')
->join("cop_topics_own b","a.id=b.ct_id")
->where($where)->find();
}
}
或者使用$this-> 来代替Db::name(‘cop_topics’) ,本来就是cop_topics模型
public function adminGetTopics($id){
$where[]=["a.id",'=',$id];
return $this->alias('a')
->join("cop_topics_own b","a.id=b.ct_id")
->where($where)->find();
}