Answer the question
In order to leave comments, you need to log in
Why does an error occur when going to a page with id in yii2?
When going to the /view/4 page (or any other page with id after /view/), an error occurs:
An Error occurred while handling another error:
yii\base\InvalidRouteException: Unable to resolve the request: site/error in D:\OpenServer\domains\marlin-yii2-crud\vendor\yiisoft\yii2\base\Controller.php:128
Stack trace:
#0 D:\OpenServer\domains\marlin-yii2-crud\vendor\yiisoft\yii2\base\Module.php(528): yii\base\Controller->runAction('error', Array)
#1 D:\OpenServer\domains\marlin-yii2-crud\vendor\yiisoft\yii2\web\ErrorHandler.php(108): yii\base\Module->runAction('site/error')
#2 D:\OpenServer\domains\marlin-yii2-crud\vendor\yiisoft\yii2\base\ErrorHandler.php(111): yii\web\ErrorHandler->renderException(Object(yii\web\NotFoundHttpException))
#3 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\web\NotFoundHttpException))
#4 {main}
Previous exception:
yii\base\InvalidRouteException: Unable to resolve the request "view/4". in D:\OpenServer\domains\marlin-yii2-crud\vendor\yiisoft\yii2\base\Module.php:537
Stack trace:
#0 D:\OpenServer\domains\marlin-yii2-crud\vendor\yiisoft\yii2\web\Application.php(103): yii\base\Module->runAction('view/4', Array)
#1 D:\OpenServer\domains\marlin-yii2-crud\vendor\yiisoft\yii2\base\Application.php(386): yii\web\Application->handleRequest(Object(yii\web\Request))
#2 D:\OpenServer\domains\marlin-yii2-crud\web\index.php(12): yii\base\Application->run()
#3 {main}
Next yii\web\NotFoundHttpException: Page not found. in D:\OpenServer\domains\marlin-yii2-crud\vendor\yiisoft\yii2\web\Application.php:115
Stack trace:
#0 D:\OpenServer\domains\marlin-yii2-crud\vendor\yiisoft\yii2\base\Application.php(386): yii\web\Application->handleRequest(Object(yii\web\Request))
#1 D:\OpenServer\domains\marlin-yii2-crud\web\index.php(12): yii\base\Application->run()
#2 {main}
public function actionView($id = 30)
{
$one = MyList::getOne($id);
return $this->render('view', ['city' => $one]);
}
Город, c ID <? echo $city->id ?>: <? echo $city->city ?>
public static function getOne($id) {
$data = self::find()->where(['id'=>$id])->one();
return $data;
}
Answer the question
In order to leave comments, you need to log in
this is how it is indicated by the parameter to the url
if you write
everything will be ok. You need to configure routing rules
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question