如何在CI中获得最后两个uri段?

时间:2016-03-19 05:07:46

标签: php codeigniter

我想要持续两个uri细分。例如,我有一个网址:

www.abcd.com/country/state/city AND下次此网址是动态的,如下所示:

www.abcd.com/grade/country/state/city

我想要持续两个uri细分,请帮助解决这个问题。

3 个答案:

答案 0 :(得分:2)

是的,我找到了解决这个问题的方法

$record_num = $this->uri->segment_array();
echo "last - ".$record_num[count($record_num)];
echo "<br>second last - ".$record_num[count($record_num)-1];
exit;

答案 1 :(得分:1)

您可以像这样使用uri细分。 www.abcd.com/后的任何内容都是uri段

echo $this->uri->segment(1); // This should echo grade

echo $this->uri->segment(2); // This should echo country

echo $this->uri->segment(3); // This should echo state

echo $this->uri->segment(4); // This should echo city

细分userguide

答案 2 :(得分:1)

您可以使用

来实现它
if ($this->uri->segment(1) == "country") {
    echo $this->uri->segment(2); //  echo state

    echo $this->uri->segment(3); //   echo city
}
if ($this->uri->segment(1) == "grade") {
    echo $this->uri->segment(3); //  echo state

    echo $this->uri->segment(4); //   echo city
}