yyladmin 连表查询
文章描述:
yylAdmin连表查询使用leftJoin查询
app/admin/controller/xxx/xxx.php
默认where条件is_delete = 0
$where = $this->where(where_delete());
打印$where条件
Array ( [0] => Array ( [0] => is_delete [1] => = [2] => 0 ) )
在$where里面添加条件
array_push($where, array('office_id', '=', $office_id));
app/common/xxx/xxx/xxx.php
处理where条件
$model = $model->alias('m');
/* where */
foreach ($where as $k=>$v)
{
foreach ($v as $key=>$val)
{
if($key == 0){
$where[$k][$key] = 'm.'.$val;
}
}
}
打印
Array ( [0] => Array ( [0] => m.is_delete [1] => = [2] => 0 ) )
0
连表
$model = $model->Leftjoin(['lbs_city'=>'t'],'m.city = t.code')->Leftjoin(['lbs_setting_city_office'=>'l'],'m.office_id = l.id');
查询
$list = $model->field( "m.*, t.name as city_name, if(m.office_id=0,'本部',l.name) as office_name" )->where($where)->page($page)->limit($limit)->order($order)->select()->toArray();
发布时间:2023/10/09
发表评论