Yii2 分页与自定义 url 规则 [英] Yii2 Paging with custom url rules
本文介绍了Yii2 分页与自定义 url 规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用以下自定义规则在应用程序中创建分页
I'm trying to create paging in an application with the following custom rules
'enablePrettyUrl' => true,
'rules' => [
'/<id:\d+>' => 'news/view',
'/<link>' => 'news/view',
'/<technology>/<news>' => 'category/index',
'/<technology>/<tags>/<title>' => 'category/tag',
'<controller:\w+>/<action:\w+>/<id:\d+>' =>'<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',]
那么我如何编写分页规则来创建这样的网址
So how do I write the rule for paging which creates a url like this
http://localhost/project/frontend/web/site/index?page=2&per-page=3
我已经试过了
'
但它转向了这条规则
<代码>'/<技术>/<新闻>'=>'类别/索引',
推荐答案
如果其他人遇到类似的问题,我通过为基本 url 创建一个路由来解决这个问题,如下所示:
In case someone else encounters a similar problem, I solved this by creating a route for the base url like so:
'site/
然后我用 page 参数创建了一个路由
then I created a route with the page parameter
'site/
一切都像魅力一样
这篇关于Yii2 分页与自定义 url 规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文