Muhamad Yulianto
Muhamad Yulianto

Reputation: 1663

Codeigniter if else uri segment double if

I have codeigniter code and want to create url if else using uri segment, fir first line it working well, but i have trouble for second line to hide segment 2 for this url

i want to make if url is domain.com/favorite will display true, domain.com/favorite/me will display false, and else is false

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

Upvotes: 0

Views: 1656

Answers (2)

Muhamad Yulianto
Muhamad Yulianto

Reputation: 1663

i got this script working for me

conditional A= domain.com/favorite will display "True" conditional B= domain.com/any and domain.com/favorite/any will display "False"

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

Upvotes: 1

user4419336
user4419336

Reputation:

You may need to use Boolean or || plus the uri segments do not work with commas.

Try This code below

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

  echo "Working";

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

    echo "False";

} else {

    echo "FALSE";

} 

Or

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

  echo "Working";

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

    echo "False";

} else {

    echo "FALSE";

} 

Upvotes: 0

Related Questions