Добрый вечер.
Как вариант, можно сделать так:
class PageController extends AppController
{
public function actionView($alias)
{
$page = Page::find()->where(['alias' => $alias])->one();
if(empty($page)){
throw new HttpException(404, 'Страница не найдена.');
}
$contact = new ContactForm();
return $this->render('view', ['page' => $page, 'contact' => $contact]);
}
}
Вынесите в отдельный метод, будет меньше кода в действии
$page = Page::find()->where(['alias' => $alias])->one();
if(empty($page)){
throw new HttpException(404, 'Страница не найдена.');
}