S
S
Sergey Beloventsev2016-08-19 18:47:54
Yii
Sergey Beloventsev, 2016-08-19 18:47:54

Why doesn't the error fire and throw out a 404 page?

Here is the actual controller

public function actionOnepage($slug=null){
            if($slug==null){
                $page=Pages::find()->all();
            }else{
                $page=Pages::findOne(['slug_pages'=>$slug]);
            }
            return $this->render('onepage',[
                'page'=>$page
            ]);
    
        }

I make a non-existent request in advance, but the exeption "Page not found" still does not work, what did I do wrong, do not tell me? here is the request from the debugger
SELECT * FROM `fl_pages` WHERE `slug_pages`='anna-kareninaрргеав'
        C:\OpenServer\domains\film.lc\frontend\controllers\PageController.php (29)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2016-08-19
@Sergalas

$page = Pages::findOne(['slug_pages'=>$slug]);
if ($page === null) {
    throw new \yii\web\NotFoundHttpException('Page not found.');
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question