繁体   English   中英

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

[英]what is the use of $this->uri->segment(3) in codeigniter pagination

听到的是我的代码

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); 它停止工作

这使您可以从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

CodeIgniter用户指南说:

$这个 - > URI->段(n)的

允许您检索特定的细分。 其中n是您要检索的段号。 细分从左到右编号。 例如,如果您的完整网址是: 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'

在您的代码中, $this->uri->segment(3)引用您在查询中使用的分页offset 根据你的$config['base_url'] = base_url().'index.php/papplicant/viewdeletedrecords/' ; $this->uri->segment(3)即段3指的是偏移量。 第一个段是controller ,第二个是method ,之后是作为segments发送到控制器的parameters

默认情况下,如果段不存在,则函数返回FALSE(布尔值)。 有一个可选的第二个参数,允许您在缺少段时设置自己的默认值。 例如,这将告诉函数在发生故障时返回数字零:$ product_id = $ this-> uri-> segment(3,0);

它有助于避免编写如下代码:

[if ($this->uri->segment(3) === FALSE)
{
    $product_id = 0;
}
else
{
    $product_id = $this->uri->segment(3);
}]

假设你有一个像http://www.example.com/controller/action/arg1/arg2这样的网址

如果您想知道在此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'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM