public function actionDelete() { $data = Yii::$app->request->post(); if (empty($data['phone']) || empty('usertocardid')) { return array('flag' => 0, 'msg' => 'no enough arg!'); } $user = Users::findOne(['phone' => $data['phone']]); if (!$user) { return array('flag' => 0, 'msg' => 'user not exist!'); } $model = Usertocards::findOne(['id' => $data['usertocardid']]); if (!$model) { return array('flag' => 0, 'msg' => 'usertocard not exist!'); } if ($model['userid'] != $user['id']) { return array('flag' => 0, 'msg' => 'not the owner!'); } if ($model->delete()) { return array('flag' => 1, 'msg' => 'delete success!'); } else { return array('flag' => 0, 'msg' => 'delete failure!'); } }
/** * Finds the Usertocards model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Usertocards the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Usertocards::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }