douhuiwan5141 2014-03-12 18:44
浏览 54
已采纳

分页CodeIgniter覆盖基本URL

My website pagination is inside the "home" function in the "user_area" controller file. I followed the example from this page Pagination

The pagination works fine except that it messes my base_url. When I click the pagination links, and then click on a link in the website navbar, the "home" is added to all the links.

Any help is welcome.

Controller:

    public function home(){
    if($this->session->userdata('is_logged_in')){

        $this->load->model('model_match');
        $this->load->model('model_user');
        $this->load->model('model_msg');    

        $pagination = array();

        $pagination["total_rows"] = $this->model_match->countMatches();
        $pagination["per_page"] = 2;
        $pagination["uri_segment"] = 3;
        $choice = $pagination["total_rows"] / $pagination["per_page"];
        $pagination["num_links"] = round($choice);
        $pagination['base_url'] = base_url('user_area/home');
        $this->pagination->initialize($pagination);

        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $data["videos"] =  $this->model_match->getAllMatches($pagination["per_page"], $page);
        $data["links"] = $this->pagination->create_links();


        $data['count_unread_msgs'] = $this->model_msg->countUnreadMsgs($this->session->userdata('user'));
        $data['count_unread_hearts'] = $this->model_msg->countUnreadHearts($this->session->userdata('user'));



        $data['user_name'] = $this->session->userdata('user');
        //$data['videos'] = $this->model_match->getAllMatches();
        $this->load->view('user/matches',$data);

        }else{
            redirect('home');
            }

    }

Nav Bar :

        <nav>      


                 <a  href="home">Home</a>   
                  <a  href="message_center">Messages</a>   
                 <a href="account">Account</a>

                   <a   href="library">Portfolio</a>
                 <a   href="favorites">Favorites</a>   
                 <a href="viewer-help.php">Help / FAQ </a> -->
                 <a  href="toolkit">Toolkit</a>   
                   <a href="<?php echo base_url()."login/logout";?>">Logout</a>


                <?php searchOptions();?>

    </nav>
  • 写回答

1条回答 默认 最新

  • dongshuming7131 2014-03-12 20:02
    关注

    theres your problem

    <a href="toolkit">Toolkit</a> is a relative path link,

    you should be doing something like this on all your nav links as a best practice:

    <a href="<?php echo base_url('toolkit');?>">Toolkit</a>

    or

    <a href="<?=base_url('toolkit');?>">Toolkit</a>

    if your server supports short open tags

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?