一、对应表进行建模 新建数据视图表UserViewModel.class.php
二、继承ViewModel 三表关联起来
<?php
class UserViewModel extends ViewModel{
public $viewFields=array(
'User'=>array('id','name','_as'=>'u','_type'=>'left'),
'UserInfo'=>array('email','mobile','_as'=>'ui','_on'=>'ui.user_id=u.id'),
'Dept'=>array('name'=>'dept','_on'=>'u.dept_id=Dept.id')
);
}
?>
三、设置动作IndexAction.class.php
<?php
class IndexAction extends Action {
public function index(){
header('Content-Type:text/html;charset=utf-8');//解决乱码
$dao=D('UserView');//创建数据对象
$where['u.id']=1;//条件
dump($dao->where($where)->find());
echo $dao->getlastsql();
}
?>
二、继承ViewModel 三表关联起来
<?php
class UserViewModel extends ViewModel{
public $viewFields=array(
'User'=>array('id','name','_as'=>'u','_type'=>'left'),
'UserInfo'=>array('email','mobile','_as'=>'ui','_on'=>'ui.user_id=u.id'),
'Dept'=>array('name'=>'dept','_on'=>'u.dept_id=Dept.id')
);
}
?>
三、设置动作IndexAction.class.php
<?php
class IndexAction extends Action {
public function index(){
header('Content-Type:text/html;charset=utf-8');//解决乱码
$dao=D('UserView');//创建数据对象
$where['u.id']=1;//条件
dump($dao->where($where)->find());
echo $dao->getlastsql();
}
?>