123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- namespace plugins\donation\controllers;
- use Yii;
- use plugins\donation\models\Donation;
- use yii\data\ActiveDataProvider;
- use yii\web\Controller;
- use yii\web\NotFoundHttpException;
- use yii\filters\VerbFilter;
- /**
- * 捐赠管理
- */
- class AdminController extends Controller
- {
- public function behaviors()
- {
- return [
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
- 'delete' => ['post'],
- ],
- ],
- ];
- }
- /**
- * 捐赠列表
- * @return mixed
- */
- public function actionIndex()
- {
- $dataProvider = new ActiveDataProvider([
- 'query' => Donation::find(),
- 'sort' => [
- 'defaultOrder' => [
- 'id' => SORT_DESC
- ]
- ]
- ]);
- return $this->render('index', [
- 'dataProvider' => $dataProvider,
- ]);
- }
- /**
- * 捐赠详情
- * @param integer $id
- * @return mixed
- */
- public function actionView($id)
- {
- return $this->render('view', [
- 'model' => $this->findModel($id),
- ]);
- }
- /**
- * 新建捐赠
- * @return mixed
- */
- public function actionCreate()
- {
- $model = new Donation();
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- return $this->redirect(['view', 'id' => $model->id]);
- } else {
- return $this->render('create', [
- 'model' => $model,
- ]);
- }
- }
- /**
- * 编辑捐赠
- * @param integer $id
- * @return mixed
- */
- public function actionUpdate($id)
- {
- $model = $this->findModel($id);
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- return $this->redirect(['view', 'id' => $model->id]);
- } else {
- return $this->render('update', [
- 'model' => $model,
- ]);
- }
- }
- /**
- * 删除捐赠
- * @param integer $id
- * @return mixed
- */
- public function actionDelete($id)
- {
- $this->findModel($id)->delete();
- return $this->redirect(['index']);
- }
- /**
- * Finds the Donation model based on its primary key value.
- * If the model is not found, a 404 HTTP exception will be thrown.
- * @param integer $id
- * @return Donation the loaded model
- * @throws NotFoundHttpException if the model cannot be found
- */
- protected function findModel($id)
- {
- if (($model = Donation::findOne($id)) !== null) {
- return $model;
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
- }
|