CodeIgniter Forums
Can someone please explain this to me - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Can someone please explain this to me (/showthread.php?tid=3597)



Can someone please explain this to me - El Forum - 10-12-2007

[eluser]bosco500[/eluser]
Can someone please explain this code to me? I was browsing through the design on the freakauth_demo, trying to understand the design. This line of code is from menu.php (view)

Code:
<?php $ci_uri = trim($this->uri->uri_string(), '/'); $att = ' id="active"';?>
    <ul id="navlist">
        <li&lt;?= $ci_uri == ''? $att: ''?&gt;>&lt;?=anchor('', 'home')?&gt;</li>
        <li&lt;?= substr($ci_uri, 0, 7) == 'example'? $att: ''?&gt;>&lt;?=anchor('example', 'examples')?&gt;</li>
        <li&lt;?= $ci_uri == $this->config->item('FAL_login_uri')? $att: ''?&gt;>&lt;?=anchor($this->config->item('FAL_login_uri'), 'login')?&gt;</li>
        <li&lt;?= $ci_uri == $this->config->item('FAL_register_uri')? $att: ''?&gt;>&lt;?=anchor($this->config->item('FAL_register_uri'), 'register')?&gt;</li>
        <li&lt;?= $ci_uri == $this->config->item('FAL_forgottenPassword_uri')? $att: ''?&gt;>&lt;?=anchor($this->config->item('FAL_forgottenPassword_uri'), 'forgotten password')?&gt;</li>
        <li&lt;?= $ci_uri == $this->config->item('FAL_changePassword_uri')? $att: ''?&gt;>&lt;?=anchor($this->config->item('FAL_changePassword_uri'), 'change password')?&gt;</li>
        <li&lt;?= substr($ci_uri, 0, 5) == 'admin'? $att: ''?&gt;>&lt;?=anchor('admin', 'admin')?&gt;</li>
    </ul>

Why does every <li> have
Code:
&lt;?= $ci_uri == $this->config->item('FAL_login_uri')? $att: ''?&gt;>&lt;?=anchor($this->config->item('FAL_login_uri'), 'login')?&gt;

I realize that $ci_uri is an object being set, but what is the ? $att: '' for? Also why is substr used?

Thanks for the help!


Can someone please explain this to me - El Forum - 10-12-2007

[eluser]Armchair Samurai[/eluser]
condtion ? expression1 : expression2 is a ternary operator. Think of it basically like and if/then/else structure.


Can someone please explain this to me - El Forum - 10-12-2007

[eluser]sergitin[/eluser]
hey brother
try this

Code:
$a=1;
echo ($a)?"A exists":'A not exists';

and then apply to your code


Can someone please explain this to me - El Forum - 10-12-2007

[eluser]bosco500[/eluser]
[quote author="sergitin" date="1192216838"]hey brother
try this

Code:
$a=1;
echo ($a)?"A exists":'A not exists';

and then apply to your code[/quote]

Thanks to both of you. Great example