Codeigniter Pagination having page number in the m

2019-06-06 11:26发布

问题:

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