Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 39 |
| SiteController | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
42.00 | |
0.00% |
0 / 39 |
| behaviors | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 15 |
|||
| actions | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
| actionIndex | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 6 |
|||
| findModel | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 7 |
|||
| <?php | |
| namespace api\controllers; | |
| use Yii; | |
| use yii\web\Controller; | |
| use yii\web\NotFoundHttpException; | |
| use yii\filters\AccessControl; | |
| use common\models\Page; | |
| /** | |
| * Site controller | |
| */ | |
| class SiteController extends Controller | |
| { | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function behaviors() | |
| { | |
| return [ | |
| 'access' => [ | |
| 'class' => AccessControl::className(), | |
| 'only' => ['index'], | |
| 'rules' => [ | |
| [ | |
| 'actions' => ['index'], | |
| 'allow' => true, | |
| 'roles' => ['supervisor', 'admin'], | |
| ], | |
| ], | |
| ], | |
| ]; | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function actions() | |
| { | |
| return [ | |
| 'error' => [ | |
| 'class' => 'yii\web\ErrorAction', | |
| ], | |
| 'captcha' => [ | |
| 'class' => 'yii\captcha\CaptchaAction', | |
| 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, | |
| ], | |
| ]; | |
| } | |
| /** | |
| * Displays homepage. | |
| * | |
| * @return string | |
| */ | |
| public function actionIndex() | |
| { | |
| $model = $this->findModel('admin-home-page'); | |
| return $this->render('page',[ | |
| 'model' => $model | |
| ]); | |
| } | |
| /** | |
| * Finds the Page model based on its primary key value. | |
| * If the model is not found, a 404 HTTP exception will be thrown. | |
| * @param string $alias | |
| * @return Page the loaded model | |
| * @throws NotFoundHttpException if the model cannot be found | |
| */ | |
| protected function findModel($alias) | |
| { | |
| if (($model = Page::findOne(['alias' => $alias])) !== null) { | |
| return $model; | |
| } else { | |
| throw new NotFoundHttpException('The requested page does not exist.'); | |
| } | |
| } | |
| } |