0

我编辑了我的模型->搜索功能的条件,只查看具有相同业务 ID 的数据,但现在高级搜索不起作用。

这是我模型上的代码 model->search()

  public function search() {
    // Warning: Please modify the following code to remove attributes that
    // should not be searched.

    $criteria = new CDbCriteria;

    $criteria->compare('LOVEAGENT_ID', $this->LOVEAGENT_ID);
    $criteria->compare('FIRST_NAME', $this->FIRST_NAME, true);
    $criteria->compare('LAST_NAME', $this->LAST_NAME, true);
    $criteria->compare('DOB', $this->DOB, true);
    $criteria->compare('PASSWORD', $this->PASSWORD, true);
    ............


    $criteria->condition = 'BUSINESS_ID=:businessID';
    $criteria->params = array(':businessID' => Yii::app()->user->businessId);

    return new CActiveDataProvider($this, array(
                'criteria' => $criteria,
            ));
}

我的管理员控制器:

   public function actionAdmin() {
        $model = new LoveAgentContactDetails('search');
        $model->unsetAttributes();  // clear any default values

        if (isset($_GET['LoveAgentContactDetails'])) {
            $model->attributes = $_GET['LoveAgentContactDetails'];
        }

        $this->render('admin', array(
            'model' => $model,
        ));
    }

和 Cgrid 视图设置在视图:

$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'love-agent-contact-details-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(

    'FIRST_NAME',
    'LAST_NAME',
    'lastLoginTime',
    'created',

    array(
        'class' => 'CButtonColumn',
    ),
),

));

4

1 回答 1

3

问题就在这里

 $criteria->condition = 'BUSINESS_ID=:businessID';

通过这种方式,您重新编写了先前准备好的条件。你可以使用CDbCriteria::addCondition,但最好的方法是

   $criteria->compare('BUSINESS_ID',Yii::app()->user->businessId);
于 2012-05-14T06:06:12.060 回答