0
下面的視圖代碼如下生成html代碼。爲什麼此代碼將html =「active」添加到html?
Q1。第一行是幹什麼的?
<?php $ci_uri = trim($this->uri->uri_string(), '/'); $att = ' id="active"';?>
Q2。爲什麼
產生id =「active」?
Q3。
<?= substr($ci_uri, 0, 7) == 'example'? $att: ''?>
<?= $ci_uri == $this->config->item('FAL_login_uri')? $att: ''?>
...
...
<?= $ci_uri == $this->config->item('FAL_changePassword_uri')? $att: ''?>
etc.
是什麼意思使用三元運算符?
查看代碼
<?php $ci_uri = trim($this->uri->uri_string(), '/'); $att = ' id="active"';?>
<ul id="navlist">
<li<?= $ci_uri == ''? $att: ''?>><?=anchor('', 'home')?></li>
<li<?= substr($ci_uri, 0, 7) == 'example'? $att: ''?>><?=anchor('example', 'examples')?></li>
<li<?= $ci_uri == $this->config->item('FAL_login_uri')? $att: ''?>><?=anchor($this->config->item('FAL_login_uri'), 'login')?></li>
<li<?= $ci_uri == $this->config->item('FAL_register_uri')? $att: ''?>><?=anchor($this->config->item('FAL_register_uri'), 'register')?></li>
<li<?= $ci_uri == $this->config->item('FAL_forgottenPassword_uri')? $att: ''?>><?=anchor($this->config->item('FAL_forgottenPassword_uri'), 'forgotten password')?></li>
<li<?= $ci_uri == $this->config->item('FAL_changePassword_uri')? $att: ''?>><?=anchor($this->config->item('FAL_changePassword_uri'), 'change password')?></li>
<li<?= substr($ci_uri, 0, 5) == 'admin'? $att: ''?>><?=anchor('admin', 'admin')?></li>
</ul>
HTML代碼
<ul id="navlist">
<li id="active"><a href="http://127.0.0.1/ci_freak_auth/index.php">home</a></li>
<li><a href="http://127.0.0.1/ci_freak_auth/index.php/example.html">examples</a></li>
<li><a href="http://127.0.0.1/ci_freak_auth/index.php/auth/login.html">login</a></li>
<li><a href="http://127.0.0.1/ci_freak_auth/index.php/auth/register.html">register</a></li>
<li><a href="http://127.0.0.1/ci_freak_auth/index.php/auth/forgotten_password.html">forgotten password</a></li>
<li><a href="http://127.0.0.1/ci_freak_auth/index.php/auth/changepassword.html">change password</a></li>
<li><a href="http://127.0.0.1/ci_freak_auth/index.php/admin.html">admin</a></li>
</ul>