首页  >  问答  >  正文

php - TP5多对多关联查询报错,能帮我看看哪边的问题吗?

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();
    }
}
PHP中文网PHP中文网2638 天前936

全部回复(1)我来回复

  • PHP中文网

    PHP中文网2017-07-05 10:48:01

    id属性不存在,看看$notFound是怎么得到的,是不是少传了参数

    回复
    0
  • 取消回复