• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
URI Segment.

#1
[eluser]aran384[/eluser]
Was wondering how do I find out what the current URI segment 3 is equal to...?

Basically I have a header that gets pulled into different pages, and usuing that header I want to know what the current page is so I can place a bit of code into the header that will relate to the page,
FYI, using variables will not work, I have multiple places to place the code, each being different for the different pages.

#2
[eluser]aran384[/eluser]
I was thinking on using the to string bit, but I do not want to use that in case I end up having something like gallery/category/picturename

So what ever I use am looking on just taking that first bit.

#3
[eluser]aran384[/eluser]
Anyone able to help me out then???...

#4
[eluser]Phil Sturgeon[/eluser]
You can use:

Code:
if($this->uri->segment(3, '') == 'magoo'):
{...}

I generally preffer to make use of:

Code:
$this->uri->router->class;
$this->uri->router->method;
$this->uri->router->directory;

as it means the code is a little more flexible when dealing with sub-directoried controllers.

#5
[eluser]aran384[/eluser]
segment 3 is being the first one???

#6
[eluser]aran384[/eluser]
Also what does the blank '' do?

#7
[eluser]Phil Sturgeon[/eluser]
It will be default return an empty string instead of an error message, always handy. 3 is the third one, 1 will be a sub-directory if you have it or the name of your controller.

#8
[eluser]aran384[/eluser]
kk, how can I add a OR statement to a If statement in PHP?

I believe it is something like || or && but couldnt find out on PHP manual how to do it?

#9
[eluser]linuxbz[/eluser]
Do you mean like:

Code:
if ( $missing or ! $authorized )
{
    echo "Sorry, friend.";
}

The operators you mentioned have a higher precedence:

Code:
$permitted = $missing || ! $authorized;

If you don't know the difference, you probably want to use 'or' or 'and'.

See
logical operators.

#10
[eluser]aran384[/eluser]
[quote author="linuxbz" date="1182811082"]Do you mean like:

Code:
if ( $missing or ! $authorized )
{
    echo "Sorry, friend.";
}

The operators you mentioned have a higher precedence:

Code:
$permitted = $missing || ! $authorized;

If you don't know the difference, you probably want to use 'or' or 'and'.

See
logical operators.[/quote]

This is what I was after, it's just I didn't know which PHP used... Whether it was them or other ones.

This has been a great help, when I get back onto my computer I will post the code that I used to whether it is right.

(Motherboard died so I am missing a computer.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.