public function userlist(){//用户列表
$res=D('UserRelation')->field('password',true)->relation(true)->select();
$this->assign('list',$res);
$this->display();
}
UserRelation模型:<?php
namespace Admin\Model;
use Think\Model\RelationModel;
class UserRelationModel extends RelationModel {
protected $connection = 'DB_CONFIG1'; //数据库连接
protected $tableName='rbac_admin_user'; //关联主表
protected $_link=array(
'rbac_admin_role'=>array( //关联副表
'mapping_type'=>self::MANY_TO_MANY, //关联关系
'mapping_name' => 'role', //关联模型名称
'mapping_order'=>'id', //关联排序字段
'mapping_limit'=>10, //关联返回的最大记录数
'foreign_key'=>'user_id', //主表外键
'relation_foreign_key'=>'role_id', //副表外键
'relation_table'=>'rbac_admin_role_user',//中间表
'mapping_fields'=>'id,name,remark' //要查询的字段
)
);
}
?>
由于TP官网限制附件大小,附件见:http://pan.baidu.com/s/1dDriszn求各位大神帮忙,小弟不胜感激
最佳答案
