1

我正在尝试在 codeigniter 中使用分页类,我的 url 看起来像这样:

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

有没有办法将页码保留在 url 中间?

谢谢

编辑:

            $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';
4

2 回答 2

5

在挖掘了 Pagination 类的代码之后,我找到了一种方法来做到这一点,但教程中的任何地方都没有提到它。

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

这可以在 url 中间生成带有页码的 url。

eg. http://www.blah.com/posts/browse/page/2/item_per_page/1;
于 2012-11-19T07:04:24.117 回答
1

文档清楚地解释了如何执行此操作。

短版:$config['uri_segment'] = 4;在您的分页配置中使用。uri_segment告诉分页类哪个 uri 段包含页面#。

于 2012-11-19T05:10:02.840 回答