控制器在yii2中改变状态的动作


controller action for changing status in yii2

我试图在我的userController中创建一个actionSuspend。但当我点击按钮更新状态时,它会将我重定向到一个空白页面,或者我创建的功能不起作用。这是我的控制器代码:

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

我的视图代码是

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

尝试

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