Advertisement
Guest User

Untitled

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