$this->uri->segment(3)在 codeigniter 分页中的用途是什么

2022-08-30 19:24:15

听到是我的代码

public function viewdeletedrecords()
{   

    if($this->session->userdata('applicant_firstname') == '')
    {
        redirect('papplicant/login') ;
    }
    $profile = $this->m_applicant->showdeletedrecods('','');                                                         
    $total_rows = count($profile) ;
    $config['base_url'] =  base_url().'index.php/papplicant/viewdeletedrecords/' ;
    $config['per_page'] = '10' ;
    $config['full_tag_open'] = '<div>' ;

    $config['full_tag_close'] = '</div>' ;

    $config['first_link'] = 'First' ;

    $config['last_link'] = 'Last' ;

    $config['use_page_numbers'] = TRUE ;

    $config['prev_link'] = '&lt;' ;

    $config['uri_segment'] = 3 ;

    $config['num_links'] = 10 ;         

    $config['cur_tag_open'] = '<b>' ;

    $config['cur_tag_close'] = '</b>' ;

    $config['total_rows'] = $total_rows ;       

    $invoicepaginate = $this->m_applicant->showdeletedrecods( $config['per_page'], $this->uri->segment(3)) ;    

    $this->pagination->initialize($config);     

    $data4 = array(                             

    'data' => $invoicepaginate                                                                                       

    ) ;

    $this->load->view('applicant', $data4);

}

在 codeigniter 中有什么用处$this->uri->segment(3)

我输入它按预期工作,但当我输入时,它停止工作$this->uri->segment(3);$this->uri->segment(4);


答案 1

这使您可以从 URI 字符串中检索信息

$this->uri->segment(n); // n=1 for controller, n=2 for method, etc

请考虑以下示例:

http://example.com/index.php/controller/action/1stsegment/2ndsegment

它会回来的

$this->uri->segment(1); // controller
$this->uri->segment(2); // action
$this->uri->segment(3); // 1stsegment
$this->uri->segment(4); // 2ndsegment

答案 2

CodeIgniter用户指南 说:

$this->尿>段(n)

允许您检索特定区段。其中 n 是要检索的段号。区段从左到右编号。例如,如果您的完整网址是这样的:http://example.com/index.php/news/local/metro/crime_is_up

段号为:

1. news
2. local
3. metro
4. crime_is_up

所以指的是你的网址结构段。通过上面的例子,将是 ,而将是 。segment$this->uri->segment(3)'metro'$this->uri->segment(4)'crime_is_up'


推荐