CakePHP 分页 - 如何删除“page:” 来自 url 以获得更好的 seo/更干净的 URL
当我使用 CakePHP Paging 时,我得到一个像这样的 url:
http://example.com/php/page:2
我必须在控制器、视图和 paths.php 中更改什么才能创建这样的工作 url:
http://example.com/php/2
When I use CakePHP Paging I get an url like this:
http://example.com/php/page:2
What do I have to change in the controller, the view and the routes.php to create a working url like this:
http://example.com/php/2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
哦,是的,现在我看到你的问题了。 那么你可以这样做:
请参阅此处了解更多详细信息:
http://bakery.cakephp.org/articles/view/basic- pagination-overview-3
另外,当然您应该做一些验证,以确保该页面是一个实际的数字,并且该页面甚至会存在,但我认为这是它的基础知识。
关于路线和景观,我从来没有尝试过,但是看看蛋糕组上的这些帖子,我认为他们有和你类似的问题。
http://www.mail-archive.com/[电子邮件受保护]/msg45878.html
Oh yes, now I see your question. Well you could do something like:
See here for more details:
http://bakery.cakephp.org/articles/view/basic-pagination-overview-3
Also, of course you should do some validation that the page is an actual number and that the page would even exist but that is the basics of it i think.
About the routes and views, I have never tried but have a look at these posts on the cake groups, I think they have a problem similar to yours.
http://www.mail-archive.com/[email protected]/msg45878.html
试试这个链接:
http://www.sakic.net/blog/changing -cakephp-pagination-urls/
Try this link:
http://www.sakic.net/blog/changing-cakephp-pagination-urls/
我的猜测是,这并不容易实现自动化,您肯定需要进行一些调整。
对于初学者,您可能必须创建自己的分页器助手并继承默认的分页器助手。 从代码的外观来看,您需要覆盖 PaginatorHelper::__pagingLink() 中的链接生成代码,但可能是numbers() 和 prev() 等,因为它们都使用页面参数创建链接。
也许更好的方法是覆盖您的 AppHelper::url(),检查那里的“page”参数并修改 url 以满足您的需求。
但是,我还没有尝试过所有这些,所以不能保证..
My guess is that this won't be easy to automate, you'll definitely need to do some tweaking.
For starters, you'll probably have to create your own paginator helper and inherit the default one. By the looks of the code, you'll need to override the link-generating code in PaginatorHelper::__pagingLink(), but probably numbers() and prev() etc.. since they all create links with the page param.
Maybe a better way would be to override your AppHelper::url(), check for the "page" param there and modify the url to accomodate your needs.
But, I haven't tried all this, so no guarantees..