public function deleteActivity($id) { $model = Activity::findOne($id); if (!$model) { return false; } if ($model->delete()) { return true; } return false; }
public function actionEditactivity() { $user = new AdminUser(); if (!$user->checkUserIsLogin()) { $this->redirect(Variable::$home_url); return; } $req = Yii::$app->request; //创建一个请求对象 $form = new ActivityForm(); $form->setScenario('update'); $id = trim($req->get('id')); if (!is_numeric($id) || $id == 0) { $this->redirect(Variable::$activityList_url); return; } //修改 if ($form->load($req->post()) && $form->validate()) { $isSuccess = (new Activity())->updateActivity($id, $form->name, $form->startTime, $form->endTime, $form->description, $form->rule, $form->isShow, $form->pcUrl, $form->wapUrl, $form->discount, $form->reduceMoney, $form->status); if ($isSuccess) { $form->addError('', '更新成功'); echo Alert::widget(['type' => Alert::TYPE_SUCCESS, 'options' => ['title' => '', 'text' => "资料更新成功", 'confirmButtonText' => "确定", 'cancelButtonText' => "取消"]]); } else { $form->addError('', '更新失败'); } } $activityModel = Activity::findOne($id); $form->name = $activityModel->name; $form->startTime = $activityModel->startTime; $form->endTime = $activityModel->endTime; $form->rule = $activityModel->rule; $form->description = $activityModel->description; $form->isShow = $activityModel->isShow; $form->pcUrl = $activityModel->pcUrl; $form->wapUrl = $activityModel->wapUrl; $form->discount = $activityModel->discount; $form->reduceMoney = $activityModel->reduceMoney; $form->status = $activityModel->status; return $this->render(Variable::$editActivity_view, ['model' => $form, 'activityModel' => $activityModel]); }
/** * Finds the Activity model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Activity the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Activity::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }