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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19293892/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 19:12:12  来源:igfitidea点击:

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

phpcodeigniter

提问by nilesh

hear is my code

听到是我的代码

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

}

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

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

whan I enter $this->uri->segment(3);it works as expected but when I enter $this->uri->segment(4);it stops working

焕我进入$this->uri->segment(3);它工作正常,但是当我进入$this->uri->segment(4);它停止工作

回答by Moyed Ansari

This provides you to retrieve information from your URI strings

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

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

Consider this example:

考虑这个例子:

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

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

it will return

它会回来

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

回答by geomagas

CodeIgniter User Guidesays:

CodeIgniter 用户指南说:

$this->uri->segment(n)

Permits you to retrieve a specific segment. Where n is the segment number you wish to retrieve. Segments are numbered from left to right. For example, if your full URL is this: http://example.com/index.php/news/local/metro/crime_is_up

The segment numbers would be this:

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

$this->uri->segment(n)

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

段号是这样的:

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

So segmentrefers to your url structure segment. By the above example, $this->uri->segment(3)would be 'metro', while $this->uri->segment(4)would be 'crime_is_up'.

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

回答by Nil'z

In your code $this->uri->segment(3)refers to the pagination offsetwhich you use in your query. According to your $config['base_url'] = base_url().'index.php/papplicant/viewdeletedrecords/' ;, $this->uri->segment(3)i.e segment 3 refers to the offset. The first segment is the controller, second is the method, there after comes the parameterssent to the controllers as segments.

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

回答by Rushi

By default the function returns FALSE (boolean) if the segment does not exist. There is an optional second parameter that permits you to set your own default value if the segment is missing. For example, this would tell the function to return the number zero in the event of failure: $product_id = $this->uri->segment(3, 0);

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

It helps avoid having to write code like this:

它有助于避免编写这样的代码:

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

回答by phpnerd

Let's say you have a url like this http://www.example.com/controller/action/arg1/arg2

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

If you want to know what are the arguments that are being passed in this url

如果你想知道这个 url 中传递的参数是什么

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

Output will be:

输出将是:

array (size=2)
  0 => string 'arg1'
  1 => string 'arg2'