/** * @param \yii\base\Application $app */ public function bootstrap($app) { $model = new Router(); $rules = $model->find()->all(); $dbRules = []; foreach ($rules as $rule) { $dbRules[] = ['pattern' => $rule->pattern, 'route' => $rule->route, 'suffix' => $rule->suffix ? $rule->suffix : false, 'defaults' => $rule->defaults ? json_decode($rule->defaults, true) : array()]; } if (!empty($dbRules)) { $app->urlManager->addRules($dbRules, false); } }
/** * Finds the Router model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Router the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Router::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }