CodeIgniter Forums

Full Version: Wanted to verify syntax.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]baazil1[/eluser]
Code:
<?php if (($this->uri->uri_string() == '' || $this->uri->uri_string() == '/homepage') && $intranetContest == 'on') { ?>

Basically, the homepage is either http://intranet/ or http://intranet/homepage ... so if the contest is "on" and either statement is true, the above works. I just wanted to verify the syntax.

Did I get it right or is the a better way to write it?

El Forum

[eluser]PhilTem[/eluser]
Your syntax should be right (maybe you need to remove the leading / at '/homepage' though, I'm not quite sure).

However, I'd recommend using

Code:
<?php if ( $this->uri->rsegment(1) == 'homepage' && $intranetContest == 'on' ) : ?>

since it's easier readable, faster written and less error prone.

This will work if and only if we're assuming that 'homepage' is your default_controller as set in config/routes.php and all requests to that page aren't routed any further. The 'r' in front of 'segment' is wanted to use the routed segments, otherwise, if there was no URI given, 'segment(1)' would return an empty string while 'rsegment(1)' returns 'homepage'.