21

私のコードを聞く

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);

}

$this->uri->segment(3)codeigniterでの使用は何 ですか

入力$this->uri->segment(3);すると期待どおりに機能しますが、入力すると機能しなくなり$this->uri->segment(4);ます

4

5 に答える 5

57

これにより、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
于 2013-10-10T10:59:18.233 に答える
16

CodeIgniter ユーザーガイド言います:

$this->uri->segment(n)

特定のセグメントを取得できます。n は取得するセグメント番号です。セグメントは左から右に番号が付けられます。たとえば、完全な URL が次の場合: http://example.com/index.php/news/local/metro/crime_is_up

セグメント番号は次のようになります。

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

だからsegmentあなたのURL構造セグメントを指します。上記の例で$this->uri->segment(3)は、 になりますが'metro'、 に$this->uri->segment(4)なります'crime_is_up'

于 2013-10-10T11:04:56.303 に答える
4

コードでは、クエリで使用$this->uri->segment(3)するページネーションoffsetを参照します。あなたによると$config['base_url'] = base_url().'index.php/papplicant/viewdeletedrecords/' ;$this->uri->segment(3)つまりセグメント3はオフセットを指します。最初のセグメントはcontroller、2 番目は でmethod、その後にparametersとしてコントローラに送信されsegmentsます。

于 2013-10-10T10:59:39.783 に答える
0

http://www.example.com/controller/action/arg1/arg2のような URL があるとし ます。

この URL で渡される引数を知りたい場合

$param_offset=0;
$params = array_slice($this->uri->rsegment_array(), $param_offset);
var_dump($params);

出力は次のようになります。

array (size=2)
  0 => string 'arg1'
  1 => string 'arg2'
于 2015-09-04T05:19:20.643 に答える