一开始也看了些资料,但是好像都不起作用。所以只能将生成的HTML进行处理,处理为自己需要的伪静态结果。

新增公共静态方法在模板中调用:

/**

* 处理分页中伪静态

* @param $pages

* @return mixed|string

* @throws \Exception

*/

public static function pageDispose($pages)

{

$html = LinkPager::widget([

'pagination' => $pages,

'nextPageLabel' => '下一页',

'prevPageLabel' => '上一页',

]);

$preg = '/<a .*?href="(.*?)".*?>/is';

preg_match_all($preg, $html, $match);

for ($i = 0; $i < count($match[1]); $i++)

{

$array = parse_url($match[1][$i]);

$pathArray = pathinfo($array['path']);

parse_str($array['query'], $url_params_arr);

if (!empty($url_params_arr['page'])) {

$page = $url_params_arr['page'];

$filename = $pathArray['filename'] . '-' . $page . '.html';

$html = str_replace($match[1][$i], $filename, $html);

}

}

return $html;

}

yii2 将分页url处理为伪静态Rewrite模板中使用:

<?= \frontend\controllers\BaseController::pageDispose($pages);

?>

main.php配置文件: 

'list-<id:\d+>-<page:\d+>' => 'site/list', //分页

 文章地址:http://www.ningmengjishu.com/yii/3.html

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-05
  • 2022-03-07
猜你喜欢
  • 2021-07-10
  • 2021-10-12
  • 2021-05-26
  • 2021-11-20
  • 2021-09-27
  • 2021-10-19
  • 2022-02-26
相关资源
相似解决方案