Codeigniter Pagination having page number in the middle of url

走远了吗. 提交于 2019-12-23 03:52:11

问题


I'm trying to use pagination class in codeigniter and my url looks something like this:

blah.com/posts/browse/page/1/item_per_page/10

is there anyway to keep the page number in the middle of url?

Thanks

EDIT:

            $this->load->library('pagination');
            $uri = $this->uri->uri_to_assoc();
            $page = null;
            $item_per_page = null;
            if (count($uri))
            {
                    foreach ($uri as $key => $value)
                    {
                            $$key = $value;
                    }
            }
            $config['base_url'] = base_url('posts/browse/page//item_per_page/1');
            $config['uri_segment'] = 4;
            $config['per_page'] = '1';

回答1:


After digging through code of Pagination class, I found a way to do this, but it wasn't mentioned anywhere in the tutorial.

            $config['base_url'] = base_url('posts/browse');
            $config['prefix'] = '/page/';
            $config['suffix'] = '/item_per_page/1';
            $config['uri_segment'] = 4;

this can generate urls with page number in the middle of the url.

eg. http://www.blah.com/posts/browse/page/2/item_per_page/1;



回答2:


The documentation clearly explains how to do this.

Short version: use $config['uri_segment'] = 4; in your pagination config. uri_segment tells the pagination class which uri segment contains the page #.



来源:https://stackoverflow.com/questions/13447709/codeigniter-pagination-having-page-number-in-the-middle-of-url

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