How do I create an if statement saying something like this?
Basically, how do you use the URI class to determine if there is a value in any segment?
$segment = value_of_any_segment;
if($segment == 1{
do stuff
}
I know this is pretty elementary, but I don’t totally understand the URI class…
Your question is a little unclear to me, but I’ll try to help. Are you wondering how to determine if a particular segment exists or if it contains a specific value?
As you are probably aware, you can use the URI class to access the specific URI segments. Using
yoursite.com/blog/article/123as an example,blogis the 1st segment,articleis the 2nd segment, and123is the 3rd segment. You access each using$this->uri->segment(n)You then can construct if statements like this:
Hope that helps! Let me know if not and I can elaborate or provide additional information.
Edit:
If you need to determine if a particular string appears in any segment of the URI, you can do something like this:
A note regarding strpos() (from the PHP documentation):
I hope my edit helps. Let me know if I can elaborate.