Answer the question
In order to leave comments, you need to log in
How to write a regular expression for a URL?
I set up an advanced CNC in the project, for viewing pages of one news or one project in the controller, one action view is used, because the template is the same:
public function actionView($className, $id, $title)
{
switch ($title) {
case 0:
$title = 'Проекты';
$route = 'site/projects';
break;
case 1:
$title = 'Новости';
$route = 'site/news';
break;
}
if (($model = $className::findOne($id)) !== null) {
return $this->render('view', [
'model' => $model,
'title' => $title,
'route' => $route,
]);
}
throw new NotFoundHttpException('The requested page does not exist.');
}
site/view?className=common%5Cmodels%5CNews&id=1&title=1
. /news-1
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question