接线员"! "不与"&&"算子

时间:2014-08-14 06:20:07

标签: php codeigniter

以下是我的代码:

<?php
$acl_test = "companies";
$act_test2 = "contractor";

if (!($this->acl->hasPermission($acl_test)) && ($this->acl->hasPermission($acl_test2))) {
    ?>

    <li <?php print ($selected == 'companies' || $selected == 'contractor') ? 'class="selected"' : ''; ?>>
        <a class="top-level" href="#">Clients</a>
        <ul>
            <li><a href="<?php print site_url('companies'); ?>">Company</a></li>
            <li><a href="<?php print site_url('contractors'); ?>">Contractor</a></li>
        </ul>
    </li>
<?php } ?>

现在,我想要做的基本上是,我正在验证登录用户是否有权查看以下链接。如果我在每个链接上单独检查,这可以正常工作。虽然我的任何用户都拥有他能够看到Clients链接的权限。现在,如果任何用户没有查看链接的任何权限,那么他也不应该看到Clients链接。但逻辑运算有问题。 有什么建议吗?

谢谢

2 个答案:

答案 0 :(得分:2)

  

虽然任何用户都拥有他的权限   能够看到客户端链接。现在,如果任何用户没有任何用户   查看链接的权限,然后他不应该看到客户端   链接。

你的意思是,如果任何一个权限是真的,你会让用户看到链接? 如果是这样,你为什么不试试:

if($this->acl->hasPermission($acl_test) || $this->acl->hasPermission($acl_test2)){
     // do something
}

答案 1 :(得分:1)

if (!($this->acl->hasPermission($acl_test)) && ($this->acl->hasPermission($acl_test)))等于if (0 && 1),它始终等于0.

您可能在&&

之后没有使用正确的功能/代码