1.刚接触TP5,看了手册里的关联模型也是云里雾里,上来求助下~~还望解答。先贴上报错截图
2.模型代码如下
namespace app\index\model;
use think\Model;
class User extends Model{
public function group(){
//用户表 belongsToMany 用户组表(关联模型,中间表,关联id1,关联id2)
return $this->belongsToMany('Group','auth_group_access','uid','group_id');
}
}
3.控制器代码如下
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Request;
use app\index\model\User as Usermodel;
class User extends Controller{
//用户列表
public function index(){
$user = new Usermodel();
$data = $user->group;
p($data);die;
$this->assign('v',$data);
return $this -> fetch();
}
}