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

泄露秘密 提交于 2019-12-05 11:55:24

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

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

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