public function parseRequest($manager, $request)
 {
     if (trim($request->getPathInfo(), '/') == $this->route && $request->get('id') && Categories::findOne($request->get('id'))) {
         header("Location:" . \Yii::$app->urlManager->createUrl([$this->route, 'id' => $request->get('id')]), true, 301);
         exit;
     }
     preg_match($this->pattern, \Yii::$app->request->getPathInfo(), $matches);
     $matches = $this->substitutePlaceholderNames($matches);
     $root = explode('/', trim($request->getPathInfo(), '/'));
     if (!isset($matches['parent'], $matches['alias']) && isset($root[1])) {
         $matches['alias'] = $root[1];
     }
     if (!isset($matches['alias'])) {
         return parent::parseRequest($manager, $request);
     }
     $model = Categories::findOne(['alias' => $matches['alias']]);
     if (!$model) {
         return parent::parseRequest($manager, $request);
     }
     if (isset($matches['parent']) && !Categories::findOne(['alias' => $matches['parent']])) {
         throw new NotFoundHttpException('Страница не найдена');
     }
     return [$this->route, ['id' => $model->id]];
 }
 /**
  * Finds the Categories model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Categories the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Categories::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }