Welcome Guest, Not a member yet? Register   Sign In
Can someone please explain this to me
#1

[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!
#2

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

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

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

and then apply to your code
#4

[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




Theme © iAndrew 2016 - Forum software by © MyBB