简体   繁体   中英

controller action for changing status in yii2

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')]);
    },

Try with

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

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM