0

我正在尝试为子查询编写代码

select * from mob_reg where name in (select name from auth where
parent ="naga");

我遵循了所有这些答案

[子查询 ActiveRecord Yii [如何为 CActiveDataProvider 设置多个条件?

但是我得到了 foreach() 的无效参数。

   $model=new MobReg('search');
$model->unsetAttributes();


$criteria = new CDbCriteria(array(
    'select' => 't.imei, t.emp_name, t.email, t.name',
    'join' => 'INNER JOIN auth ON (t.name = auth.name AND auth.parent = :parent)',
    'group' => 't.id',
    'params' => array(':parent' => 'naga')
)); 
$dataProvider = new CActiveDataProvider('MobReg', array(
        'criteria'=>$criteria,
));

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'mob-reg-grid',
    'dataProvider'=>$dataProvider,
    'filter'=>$model,
    'columns'=>array(
        'imei',
        'emp_name',
                'email',
               'name',
        array(
            'class'=>'CButtonColumn',
        ),
    ),
)); ?>

我必须更换什么?任何想法?我哪里错了?

我想我面临的问题是引用两个不同的表,一个在子查询中,另一个在主查询中。如何处理这个?

4

1 回答 1

2

类似的东西怎么样:

$criteria = new CDbCriteria(array(
    'select' => 't.imei, t.emp_name, t.email, t.name',
    'join' => 'INNER JOIN auth ON (t.name = auth.name AND auth.parent = :parent)',
    'group' => 't.id',
    'params' => array(':parent' => 'naga')
));

$dataProvider = new CActiveDataProvider('MobReg', array(
       'criteria' => $criteria,
));

这对你有用吗?

于 2013-11-05T10:12:39.683 回答