0

I have a user table in which i have multiple roles and i am showing different user on different action by using same model search function. By this

public actionAdmin(){
$model = new User('search')
$model->unsetAttributes();
$model->userRole = UmsConfing::ADMIN;
if(isset($_GET('User')))
$model->attributes = $_GET['User'];
$this->render('userlist',arary('model'=>$model));
}

I am using this function for different roles .This works well. but now i want to show admin and operation user in same list i tried

$model->userRole = UmsConfig::ADMIN || UmsConfig:: OPERATION 

but i didn't work Please help.

1 Answer 1

1

Please you can try this below code:

public actionAdmin(){
     $model = new User('search')
     $model->unsetAttributes();
       if(isset($_GET('User')))
          $model->attributes = $_GET['User'];

     $this->render('userlist',arary('model'=>$model));
}

Below codeadd in User Model Search Function:

model/User.php

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

        $criteria = new CDbCriteria;
        $criteria->compare('id',$this->id);

        $criteria->addInCondition('userRole', array (UmsConfig::ADMIN,UmsConfig:: OPERATION));

        $criteria->compare('status',$this->status);
        $criteria->compare('is_deleted',$this->is_deleted);

        return new CActiveDataProvider($this, array(
        'criteria' => $criteria,
        'pagination' => array(
            'pageSize' => yii::app()->params->pagesize,
        ),
        'sort'=>array(
                'defaultOrder'=>array(
                        'id'=>CSort::SORT_DESC
                ),
        ),
    ));

}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for ans but I cant specify these two roles in search function of model because I have many other roles and I am using same model function.
@mamta Okay i will provide other solution for that. $model->userRole = array(UmsConfig::ADMIN,UmsConfig:: OPERATION )
Hii thanks I have used your ans createf a new search function in model and added In confition .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.