Yii CGridView: how to add a static WHERE condtion?

Posted by realtebo on Stack Overflow See other posts from Stack Overflow or by realtebo
Published on 2012-10-08T13:14:16Z Indexed on 2012/10/12 3:37 UTC
Read the original article Hit count: 91

Filed under:
|
|

I've a standard Gii created admin view, which use a CGridView, and it's showing my user table data.

the problem is that user with name 'root' must NOT BE VISIBLE.

Is there a way to add a static where condition " ... and username !='root' " ?

admin.php [view]

'columns'=>array(
    'id',
    'username',
    'password',
    'realname',
    'email',
            .....

user.php [model]

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

    $criteria=new CDbCriteria;

    $criteria->compare('id',$this->id);
    $criteria->compare('username',$this->username,true);
    $criteria->compare('password',$this->password,true);
    $criteria->compare('realname',$this->realname,true);
    $criteria->compare('email',$this->email,true);

    ......


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

© Stack Overflow or respective owner

Related posts about yii

Related posts about condition