codeigniter:分页链接显示和工作但不正确

时间:2018-04-06 05:12:06

标签: php codeigniter

每个人都是。 我在codeigniter中创建了一个项目。我下载了一个模板并开始工作。 当我使用分页分页链接显示正确,但当我点击链接时,它移动其他控制器上的链接。我不知道它是如何工作的,请帮助我 提前致谢 这里链接 enter image description here 当我点击这个然后它像这样移动而不是车辆 enter image description here 这是我的控制器代码

function vehicle()
{
    if($this->isAdmin() == TRUE)
    {
        $this->loadThis();
    }
    else
    {
        $searchText = $this->input->post('searchText');
        $data['searchText'] = $searchText;            
        //$this->load->library('pagination');            
        $count = $this->hotel_other_model->vehicle_count($searchText);
        $returns = $this->paginationCompress ( "vehicle/", $count, 5);            
        $data['vehicleRecords'] = $this->hotel_other_model->vehicle_list($searchText, $returns["page"], $returns["segment"]);
        $this->global['pageTitle'] = 'CodeInsect : Vehicle Listing';            
        $this->loadViews("hotel_other/vehicle", $this->global, $data, NULL);
    }
}

像这样的视图链接

<div class="box-footer clearfix">
                <?php echo $this->pagination->create_links(); ?>
            </div>

paginationCompress()函数在这里

function paginationCompress($link, $count, $perPage = 10) {     
    $config ['base_url'] = base_url () . $link;
    $config ['total_rows'] = $count;
    //$config ['uri_segment'] = SEGMENT;
    $config ['uri_segment'] = 2;
    $config ['per_page'] = $perPage;
    $config ['num_links'] = 5;
    $config ['full_tag_open'] = '<nav><ul class="pagination">';
    $config ['full_tag_close'] = '</ul></nav>';
    $config ['first_tag_open'] = '<li class="arrow">';
    $config ['first_link'] = 'First';
    $config ['first_tag_close'] = '</li>';
    $config ['prev_link'] = 'Previous';
    $config ['prev_tag_open'] = '<li class="arrow">';
    $config ['prev_tag_close'] = '</li>';
    $config ['next_link'] = 'Next';
    $config ['next_tag_open'] = '<li class="arrow">';
    $config ['next_tag_close'] = '</li>';
    $config ['cur_tag_open'] = '<li class="active"><a href="#">';
    $config ['cur_tag_close'] = '</a></li>';
    $config ['num_tag_open'] = '<li>';
    $config ['num_tag_close'] = '</li>';
    $config ['last_tag_open'] = '<li class="arrow">';
    $config ['last_link'] = 'Last';
    $config ['last_tag_close'] = '</li>';

    $this->pagination->initialize ( $config );
    $page = $config ['per_page'];       
    $segment = $this->uri->segment (2);
    return array (
            "page" => $page,
            "segment" => $segment
    );
}

请为此提供帮助 再次感谢提前 抱歉我的英文不好

1 个答案:

答案 0 :(得分:0)

此代码中包含搜索功能,以使搜索和分页同时工作,视图文件末尾有jQuery代码。

<script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery('ul.pagination li a').click(function (e) {
            e.preventDefault();            
            var link = jQuery(this).get(0).href;            
            var value = link.substring(link.lastIndexOf('/') + 1);
            jQuery("#searchList").attr("action", baseURL + "userListing/" + value);
            jQuery("#searchList").submit();
        });
    });
</script>

请检查代码。

jQuery("#searchList").attr("action", baseURL + "userListing/" + value);

您需要提供路线,而不是userListing。然后它将起作用。