K
K
khodos_dmitry2018-10-15 10:29:33
Yii
khodos_dmitry, 2018-10-15 10:29:33

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}

If you load the page /view , then everything is fine. Substituted id = 30 by default.
Code in controller:
public function actionView($id = 30)
    {	
    $one = MyList::getOne($id);
        return $this->render('view', ['city' => $one]);
    }

Code in \views\site\view.php
Город, c ID <? echo $city->id ?>: <? echo $city->city ?>

Code in the model:
public static function getOne($id) {
    $data = self::find()->where(['id'=>$id])->one();
    return $data;
  }

Something somewhere isn't catching the id, I suspect. But where?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
eternalfire, 2018-10-15
@khodos_dmitry

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 question

Ask a Question

731 491 924 answers to any question