D
D
Dilik Pulatov2017-07-12 11:55:50
Yii
Dilik Pulatov, 2017-07-12 11:55:50

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]
  ],

and the result is such a link when clicking
/site/category?url=auto&page=2
and not
/auto/2
how to fix it?
and if I manually typed the address /auto/2, then everything works ... in pagination, why does such a url turn out?
by the way
/site/category is because of the get-page action
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

1 answer(s)
A
Anton Morev, 2017-07-19
@amorev

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 question

Ask a Question

731 491 924 answers to any question