Codeigniter if else uri segment double if

时间:2015-01-26 03:35:30

标签: php codeigniter

我有codeigniter代码并且想要使用uri段创建url,fir第一行它运行良好,但我在第二行隐藏这个url的段2有麻烦

我想如果url是domain.com/favorite将显示为true,domain.com/favorite/me将显示false,否则为false

 <?php
    if ($this->uri->segment(1) == "favorite") 
    {
        echo "True";
    }
    elseif ($this->uri->segment(1,2) == "favorite/me")
    {
        echo "False";
    }
    else
    {
        echo "false";
    }
?>

2 个答案:

答案 0 :(得分:1)

我让这个脚本为我工作

有条件的A = domain.com/favorite 将显示&#34; True&#34; 条件B = domain.com/any和domain.com/favorite/any 将显示&#34; False&#34;

&#13;
&#13;
    <?php if ($this->uri->segment(1) == "favorite" && $this->uri->segment(2) == NULL) {
    echo "True";
	}else{
    echo "False";
    }
    ?>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

您可能需要使用布尔值或||加上uri段不能用逗号。

尝试以下代码

if ($this->uri->segment(1) == "admin") {

  echo "Working";

} elseif ($this->uri->segment(1) || $this->uri->segment(2) == "admin/dashboard") {

    echo "False";

} else {

    echo "FALSE";

} 

或者

if ($this->uri->segment(1) == "admin") {

  echo "Working";

} elseif ($this->uri->segment(1) && $this->uri->segment(2) == "admin/dashboard") {

    echo "False";

} else {

    echo "FALSE";

}