<?php
    
    namespace frontend\controllers;
    
    use common\models\Project;
    use common\models\ProjectSearch;
    use yii\web\Controller;
    use yii\web\NotFoundHttpException;
    
    /**
     * Project controller
     */
    class ProjectController extends Controller
    {
        
        /**
         * Displays project list.
         * @return string
         */
        public function actionIndex()
        {
            $searchModel = new ProjectSearch();
            $dataProvider = $searchModel->search(\Yii::$app->request->queryParams);
            $dataProvider->pagination = [
                'pageSize' => 10,
            ];
            $dataProvider->query->with('images');
            return $this->render('index', [
                'searchModel'  => $searchModel,
                'dataProvider' => $dataProvider,
            ]);
        }
        
        public function actionView($id)
        {
            $model = $this->findModel($id);
            return $this->render('view', [
                'model' => $model,
            ]);
        }
        
        private function findModel($id)
        {
            $model = Project::find()
                            ->where([ 'project.project_id' => $id ])
                            ->one();
            if(empty( $model )) {
                throw new NotFoundHttpException();
            }
            return $model;
        }
    }
