Codeigniter if else uri 段 double if

Codeigniter if else uri segment double if

我有 codeigniter 代码,想创建 url 如果使用 uri 段,第一行它运行良好,但我很难让第二行为此隐藏段 2 url

我想做如果url是domain.com/favorite会显示true,domain.com/favorite/me会显示false,else是false

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

您可能需要使用布尔值或 ||再加上 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";

} 

我得到了适合我的脚本

条件 A= 域。com/favorite 将显示 "True" 条件 B= domain.com/any and domain.com/favorite/any 将显示 "False"

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