koldaev

Сгенерированная админка для аккаунтов MMORPG Поднебесье

Nov 11th, 2019
605
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.39 KB | None | 0 0
  1. <?php
  2.  
  3. namespace app\controllers;
  4.  
  5. use Yii;
  6. use app\models\MssqlAccounts;
  7. use app\models\MssqlAccounts_search;
  8. use yii\web\Controller;
  9. use yii\web\NotFoundHttpException;
  10. use yii\filters\VerbFilter;
  11.  
  12. /**
  13.  * AccountsController implements the CRUD actions for MssqlAccounts model.
  14.  */
  15. class AccountsController extends Controller
  16. {
  17.     /**
  18.      * @inheritdoc
  19.      */
  20.     public function behaviors()
  21.     {
  22.         return [
  23.             'verbs' => [
  24.                 'class' => VerbFilter::className(),
  25.                 'actions' => [
  26.                     'delete' => ['POST'],
  27.                 ],
  28.             ],
  29.         ];
  30.     }
  31.  
  32.     /**
  33.      * Lists all MssqlAccounts models.
  34.      * @return mixed
  35.      */
  36.     public function actionIndex()
  37.     {
  38.         $searchModel = new MssqlAccounts_search();
  39.         $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  40.  
  41.         return $this->render('index', [
  42.             'searchModel' => $searchModel,
  43.             'dataProvider' => $dataProvider,
  44.         ]);
  45.     }
  46.  
  47.     /**
  48.      * Displays a single MssqlAccounts model.
  49.      * @param string $id
  50.      * @return mixed
  51.      * @throws NotFoundHttpException if the model cannot be found
  52.      */
  53.     public function actionView($id)
  54.     {
  55.         return $this->render('view', [
  56.             'model' => $this->findModel($id),
  57.         ]);
  58.     }
  59.  
  60.     /**
  61.      * Creates a new MssqlAccounts model.
  62.      * If creation is successful, the browser will be redirected to the 'view' page.
  63.      * @return mixed
  64.      */
  65.     public function actionCreate()
  66.     {
  67.         $model = new MssqlAccounts();
  68.  
  69.         if ($model->load(Yii::$app->request->post()) && $model->save()) {
  70.             return $this->redirect(['view', 'id' => $model->AccountID]);
  71.         }
  72.  
  73.         return $this->render('create', [
  74.             'model' => $model,
  75.         ]);
  76.     }
  77.  
  78.     /**
  79.      * Updates an existing MssqlAccounts model.
  80.      * If update is successful, the browser will be redirected to the 'view' page.
  81.      * @param string $id
  82.      * @return mixed
  83.      * @throws NotFoundHttpException if the model cannot be found
  84.      */
  85.     public function actionUpdate($id)
  86.     {
  87.         $model = $this->findModel($id);
  88.  
  89.         if ($model->load(Yii::$app->request->post()) && $model->save()) {
  90.             return $this->redirect(['view', 'id' => $model->AccountID]);
  91.         }
  92.  
  93.         return $this->render('update', [
  94.             'model' => $model,
  95.         ]);
  96.     }
  97.  
  98.     /**
  99.      * Deletes an existing MssqlAccounts model.
  100.      * If deletion is successful, the browser will be redirected to the 'index' page.
  101.      * @param string $id
  102.      * @return mixed
  103.      * @throws NotFoundHttpException if the model cannot be found
  104.      */
  105.     public function actionDelete($id)
  106.     {
  107.         $this->findModel($id)->delete();
  108.  
  109.         return $this->redirect(['index']);
  110.     }
  111.  
  112.     /**
  113.      * Finds the MssqlAccounts model based on its primary key value.
  114.      * If the model is not found, a 404 HTTP exception will be thrown.
  115.      * @param string $id
  116.      * @return MssqlAccounts the loaded model
  117.      * @throws NotFoundHttpException if the model cannot be found
  118.      */
  119.     protected function findModel($id)
  120.     {
  121.         if (($model = MssqlAccounts::findOne($id)) !== null) {
  122.             return $model;
  123.         }
  124.  
  125.         throw new NotFoundHttpException('The requested page does not exist.');
  126.     }
  127. }
Add Comment
Please, Sign In to add comment