controller action for changing status in yii2

1.3k views Asked by At

I tried to create a actionSuspend in my userController. But when i click the button to update the status its redirect me to a blank page or the function i created is not working. This is my Controller code:

public function actionSuspend()
    {
        $user_model = \app\models\User::find()
                    ->where(['social_worker'=>'1'])
                    ->one();
        if($user_model == 'suspend'){
            $user_model->social_worker = 'activate';
           return $this->redirect(['index']);

        }
    }

and my view code is

'suspend' => function($url,$model){
    if($model->social_worker ==1)
        return Html::a('<span class="btn btn-xs btn-danger icon-remove bigger-80"style="margin-left:5px;"></span>', $url,['title'=>Yii::t('app','Revoke social worker')]);
    },
1

There are 1 answers

4
ScaisEdge On BEST ANSWER

Try with

   if($user_model->status == 'suspend'){
           $user_model->social_worker = 'activate';
           return $this->render(['index']);

    }