Код: Выделить всё
[code=php]Скажите пожалуйста где здесь ошибка,выбивает просто что страница не найдена.
Вот модель
[code=php]public function behaviors()
{
return [
[
'class' => SluggableBehavior::className(),
'attribute' => 'title',
],
];
}
public function rules()
{
return [
[['title', 'slug'], 'string', 'max' => 128],
[['slug'], 'unique'],
];
}
}
Вот контроллер
Код: Выделить всё
public function actionView($id, $slug = null)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
protected function findModelBySlug($id,$slug)
{
if (($model = Post::findOne([ 'slug' => $slug])) !== null) {
return $model;
} else {
throw new NotFoundHttpException();
}
}
Код: Выделить всё
'rules' => [
'class' => 'yii\web\UrlManager',
'category/<id:\d+>/page/<page:\d+>' => 'category/view',
'category/<id:\d+>' => 'category/view',
'product/<id:\d+>' => 'product/view',
'search' => 'category/search',
//'post/<id:\d+>' => 'post/view',
'page/<page:\d+>' => 'post/index',
'<controller:(post)>/<slug>' => '<post>/view',
['pattern' => 'post/<id:\d+>-<slug:(.*)>', 'route'=>'post/post',
],
],