CakePHP Pagination - how to remove “page:” from url for better seo/cleaner URL

送分小仙女□ 提交于 2019-12-07 08:21:52

问题


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

回答1:


Try this link:

http://www.sakic.net/blog/changing-cakephp-pagination-urls/




回答2:


Oh yes, now I see your question. Well you could do something like:

function index($page){
  $this->paginate = array('page'=>$page);
  $this->set('stuff', $this->paginate('YourControllerName'));
}

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/cake-php@googlegroups.com/msg45878.html




回答3:


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..



来源:https://stackoverflow.com/questions/1078558/cakephp-pagination-how-to-remove-page-from-url-for-better-seo-cleaner-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!