Advertisement
agung_py

SiteController.php

Feb 22nd, 2019
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.05 KB | None | 0 0
  1. <?php
  2.  
  3. namespace app\controllers;
  4.  
  5. use Yii;
  6. use yii\filters\AccessControl;
  7. use yii\web\Controller;
  8. use yii\web\Response;
  9. use yii\filters\VerbFilter;
  10. use app\models\LoginForm;
  11. use app\models\ContactForm;
  12.  
  13. /** use app\models\KomentarForm; */
  14.  
  15. class SiteController extends Controller
  16. {
  17.     /**
  18.      * {@inheritdoc}
  19.      */
  20.     public function behaviors()
  21.     {
  22.         return [
  23.             'access' => [
  24.                 'class' => AccessControl::className(),
  25.                 'only' => ['logout'],
  26.                 'rules' => [
  27.                     [
  28.                         'actions' => ['logout'],
  29.                         'allow' => true,
  30.                         'roles' => ['@'],
  31.                     ],
  32.                 ],
  33.             ],
  34.             'verbs' => [
  35.                 'class' => VerbFilter::className(),
  36.                 'actions' => [
  37.                     'logout' => ['post'],
  38.                 ],
  39.             ],
  40.         ];
  41.     }
  42.  
  43.     /**
  44.      * {@inheritdoc}
  45.      */
  46.     public function actions()
  47.     {
  48.         return [
  49.             'error' => [
  50.                 'class' => 'yii\web\ErrorAction',
  51.             ],
  52.             'captcha' => [
  53.                 'class' => 'yii\captcha\CaptchaAction',
  54.                 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
  55.             ],
  56.         ];
  57.     }
  58.  
  59.     /**
  60.      * Displays homepage.
  61.      *
  62.      * @return string
  63.      */
  64.     public function actionIndex()
  65.     {
  66.         return $this->render('index');
  67.     }
  68.  
  69.     /**
  70.      * Login action.
  71.      *
  72.      * @return Response|string
  73.      */
  74.     public function actionLogin()
  75.     {
  76.         if (!Yii::$app->user->isGuest) {
  77.             return $this->goHome();
  78.         }
  79.  
  80.         $model = new LoginForm();
  81.         if ($model->load(Yii::$app->request->post()) && $model->login()) {
  82.             return $this->goBack();
  83.         }
  84.  
  85.         $model->password = '';
  86.         return $this->render('login', [
  87.             'model' => $model,
  88.         ]);
  89.     }
  90.  
  91.     /**
  92.      * Logout action.
  93.      *
  94.      * @return Response
  95.      */
  96.     public function actionLogout()
  97.     {
  98.         Yii::$app->user->logout();
  99.  
  100.         return $this->goHome();
  101.     }
  102.  
  103.     /**
  104.      * Displays contact page.
  105.      *
  106.      * @return Response|string
  107.      */
  108.     public function actionContact()
  109.     {
  110.         $model = new ContactForm();
  111.         if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
  112.             Yii::$app->session->setFlash('contactFormSubmitted');
  113.  
  114.             return $this->refresh();
  115.         }
  116.         return $this->render('contact', [
  117.             'model' => $model,
  118.         ]);
  119.     }
  120.  
  121.     /**
  122.      * Displays about page.
  123.      *
  124.      * @return string
  125.      */
  126.     public function actionAbout()
  127.     {
  128.         return $this->render('about');
  129.     }
  130.  
  131.     /**
  132.      * Just Hello World first Test
  133.      */
  134.     public function actionHelloWorld($nama)
  135.     {
  136.         /* echo "Halo Dunia YII2";*/
  137.         return $this->render("halo",[
  138.             "nama" =>$nama
  139.         ]);
  140.     }
  141.  
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement