【问题标题】:How to disable button using a role如何使用角色禁用按钮
【发布时间】:2018-06-28 20:54:17
【问题描述】:

我想使用角色管理员禁用按钮,这是我的代码。

<div class="footer-section">
<?php if($this->user->role !== 'admin' && $this->user->role !== 'worker') ?>
<button type="button" class="btn btn-red col-md-6 flat-box-btn" data-toggle="modal" data-target="#AddSale"><h5 class="text-bold"><?=label('PAY');?></h5></button>
</div>

它不起作用,我使用销售作为用户并且按钮仍然显示,请有人帮忙

【问题讨论】:

  • 您是要在禁用状态下显示按钮,还是要完全隐藏按钮不被添加到页面?
  • 如果角色不是管理员或工人,我正在尝试隐藏按钮先生
  • 不,先生,我正在使用 CodeIgniter
  • 您说如果角色不是管理员或工作人员,但您在代码中使用 And (&amp;&amp;) 而不是 Or,则要隐藏按钮。
  • @j08691 我是新来的先生,代码是

标签: php roles


【解决方案1】:

你需要echoif语句中的按钮。

<div class="footer-section">
<?php 
    if($this->user->role !== 'admin' && $this->user->role !== 'worker') {
        echo '<button type="button" class="btn btn-red col-md-6 flat-box-btn" data-toggle="modal" data-target="#AddSale"><h5 class="text-bold">' . label('PAY') . '</h5></button>'
    }
?>
</div>

仅当角色不是 admin 而不是 worker 时才会呈现按钮。

【讨论】:

    【解决方案2】:

    如果您只想向具有adminworker 角色的用户显示按钮,请将您的条件更改为:

    <?php if($this->user->role == 'admin' || $this->user->role == 'worker') {
        echo "<button type='button' class='btn btn-red col-md-6 flat-box-btn' data-
        toggle='modal' data-target='#AddSale'>
        <h5 class='text-bold'>".label('PAY')."</h5>
        </button>";
    }?>
    

    【讨论】:

    • 即使您没有管理员或工作人员角色,它也会显示吗?
    • 是的,先生..,它仍然显示。我尝试使用员工角色,按钮仍然显示
    【解决方案3】:
    <div class="footer-section">
    <?php if($this->user->role !== 'admin' && $this->user->role !== 'worker') 
    echo '<button type="button" class="btn btn-red col-md-6 flat-box-btn" data-toggle="modal" data-target="#AddSale"><h5 class="text-bold">'.label("PAY").'</h5></button>';?>
    </div>
    

    【讨论】:

    • 我将&lt;?php if($this-&gt;user-&gt;role !== 'admin' &amp;&amp; $this-&gt;user-&gt;role !== 'worker') 更改为&lt;?php if($this-&gt;user-&gt;role !== 'admin' &amp;&amp; $this-&gt;user-&gt;role !== 'worker') ,其余使用您的代码运行良好,谢谢先生
    猜你喜欢
    • 2011-08-24
    • 1970-01-01
    • 2021-07-09
    • 2019-09-12
    • 2019-11-24
    • 2016-08-10
    • 2016-06-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多