Answer the question
In order to leave comments, you need to log in
How Yii2 check URL before 404 error in content pages?
It was already advised to list the known controllers, but they are often added, as it is possible to leave the standard mechanism / check in the content pages before 404 showing, i.e. the last one will be [email protected] and if it throws a 404 exception, then only show a 404 error
thanks
Answer the question
In order to leave comments, you need to log in
In the application config, you can redefine the action for errors and describe any logic in it.
'errorHandler' => [
'errorAction' => 'somecontroller/someaction',
],
Hello.
--
I understand that you form links not by id, but by some column in the database, which has a string value.
so, if you are making a get request, then it's better to do it like this:
// код action
...
public function actionName($link= ''){ // обращаемся к той переменной, которая выводит get
$model = Catalog::find()->where(['link' => $link])->one(); // обращаемся к БД с вопросом, есть ли такая запись
if ($link == NULL) {return $this->redirect(['catalog']);} // если нету, то делаем редирект*
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question