CodeIgniter Forums
Wanted to verify syntax. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Wanted to verify syntax. (/showthread.php?tid=52387)



Wanted to verify syntax. - El Forum - 06-08-2012

[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?


Wanted to verify syntax. - El Forum - 06-08-2012

[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'.