【问题标题】:codeigniter's pagination does not work on first link [duplicate]codeigniter 分页在第一个链接上不起作用[重复]
【发布时间】:2012-04-02 11:27:35
【问题描述】:
$config['suffix'] = '?'.http_build_query($_GET, '', "&");

我正在将 codeigniter 的分页类用于控制器中使用 get post 的函数。一切正常。链接已生成,我可以访问每个页面等。 但是当我第一次单击时,它会将我带到网址:http://www.example.com/controller/function/ 并忽略我要求它附加在函数末尾的后缀。 例如,当 2 是我的当前页面并且我点击 1 时它不起作用: 1,2,4,5,6,... 当它自动将我带到第一个链接时,即第 1 页,它一切正常。

编辑:

$this->load->library('pagination');
        $config['suffix'] = '?'.http_build_query($_GET, '', "&");
        $config['base_url'] = 'http://www.example.com/controller/function';
        $config['total_rows'] = count($results);
        $config['per_page'] = 15;
        $config['num_links'] = 3;
$this->pagination->initialize($config);

所以,我使用 get 来构建用户之前提交的查询(这是一个搜索功能 - 所以 get 是必要的),而不是获取页面的编号!希望这更清楚。

【问题讨论】:

    标签: php codeigniter pagination


    【解决方案1】:

    -确保你有你的

    $config['base_url'] = 'http://example.com/index.php/controller/pagination_function/'
    

    设置到正确的位置。

    -你为什么使用 $_GET[''] ?你应该使用内置的codeigniter

    $this->uri->segment(n)
    

    例如。

    http://website.com/mycontroller/myfunction/myname/mybirthday
    $name = $this->uri->segment(3);
    $birthday = $this->uri->segment(4);
    

    另外你应该知道,url中函数后面的uri空间是用于所述函数的参数,如果你在之后任意添加uri而不将它们用作参数,你应该避免这样的实现。

    【讨论】:

    • 我更新了问题以澄清事情。谢谢你的回答!
    猜你喜欢
    • 2017-08-01
    • 2014-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-03
    • 1970-01-01
    • 2022-06-11
    相关资源
    最近更新 更多