PersoneController.php 1.6 KB
<?php
    
    namespace frontend\controllers;
    
    use common\models\Persone;
    use yii\web\Controller;
    use yii\web\NotFoundHttpException;

    /**
     * Class PersoneController
     *
     * @package frontend\controllers
     */
    class PersoneController extends Controller
    {
        /**
         * @return string
         */
        public function actionIndex()
        {
            $persones = Persone::find()
                               ->with('lang.alias')
                               ->all();
            
            return $this->render(
                'index',
                [
                    'persones' => $persones,
                ]
            );
        }
        
        /**
         * @param int $id
         *
         * @return string
         */
        public function actionView(int $id)
        {
            $model = $this->findModel($id);
            
            return $this->render(
                'view',
                [
                    'model' => $model,
                ]
            );
        }
        
        /**
         * @param $id
         *
         * @return array|null|\yii\db\ActiveRecord
         * @throws \yii\web\NotFoundHttpException
         */
        protected function findModel($id)
        {
            $model = Persone::find()
                            ->with('lang.alias')
                            ->where([ 'id' => $id ])
                            ->one();
            
            if (empty($model)) {
                throw new NotFoundHttpException();
            } else {
                return $model;
            }
        }
    }