Answer the question
In order to leave comments, you need to log in
How to fix CNC in Yii2 pagination?
Hello!
in the urlManager config, the cnc rules are written like this
'<url:[a-z\-_]*>' => 'site/get-page',
[
'pattern' => '<url:[a-z\-_]*>/<page:\d+>',
'route' => 'site/get-page',
'defaults' => ['page' => 1]
],
public function actionGetPage($url){
if(isset($url)){
$res = Url::find()->where(['url'=>$url,'language'=>Yii::$app->params['admin_lang']])->asArray()->one();
// debug($res); die;
if(!empty($res)){
if($res['type'] == 'category'){
$this->createMetaTagLang(Url::find()->where(['parent_id'=>$res['parent_id'],'type'=>'category'])->indexBy('language')->asArray()->all(),'category');
return Yii::$app->runAction('/site/category/',['id'=>$res['parent_id']]);
}
}
}
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
return $this->render('error');
}
Answer the question
In order to leave comments, you need to log in
The first thing that comes to mind is to write your own implementation
and override the method there
But I don't really like this method. In my free time, I will look at how it was implemented in my project and, if I understand, I will add to my answer.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question