我想根据登录会话类型显示侧栏。 这里在if条件下,如果我使用单一类型然后它工作,但如果我在if条件下使用OR(||)运算符然后它不起作用,这意味着如果我申请条件为用户和管理员然后如果员工登录此菜单是节目。
我的观点
<?php
$session_data = $this->session->userdata('admin_logged_in');
$type = $session_data['type'];
?>
<aside class="main-sidebar">
<section class="sidebar">
<?php if ($type == 'Employee' || 'admin') { ?>
<li><a href="<?php echo site_url(); ?>/admin/emp_requsition"><i class="fa fa-users"></i> <span>Employees Requsitions</span></a></li>
<?php } ?>
<?php if ($type == 'User' || 'admin') { ?>
<li><a href="<?php echo site_url(); ?>/admin/pending_list"><i class="fa fa-list "></i> <span>Pending Lists</span></a></li>
<?php } ?>
<?php if ($type == 'admin') { ?>
<li><a href="<?php echo site_url(); ?>/admin/view_reports"><i class="fa fa-list "></i> <span>View Report</span></a></li>
<?php } ?>
<li><a href="<?php echo site_url(); ?>/admin/chage_passwords"><i class="fa fa-lock "></i> <span>Change Password</span></a></li>
<li><a href="<?php echo base_url(); ?>index.php/admin/logout"><i class="fa fa-sign-out"></i> <span>Logout</span></a></li>
</ul>
</section>
</aside>
答案 0 :(得分:1)
你不能像<?php if ($type == ('Employee' || 'admin')) { ?>
你必须写它:
<?php if (($type == 'Employee') || ($type == 'admin')) { ?>
所以整个街区:
<section class="sidebar">
<?php if (($type == 'Employee') || ($type == 'admin')) { ?>
<li><a href="<?php echo site_url(); ?>/admin/emp_requsition"><i class="fa fa-users"></i> <span>Employees Requsitions</span></a></li>
<?php } ?>
<?php if ($type == 'User' || $type == 'admin') { ?>
<li><a href="<?php echo site_url(); ?>/admin/pending_list"><i class="fa fa-list "></i> <span>Pending Lists</span></a></li>
<?php } ?>
<?php if ($type == 'admin') { ?>
<li><a href="<?php echo site_url(); ?>/admin/view_reports"><i class="fa fa-list "></i> <span>View Report</span></a></li>
<?php } ?>
<li><a href="<?php echo site_url(); ?>/admin/chage_passwords"><i class="fa fa-lock "></i> <span>Change Password</span></a></li>
<li><a href="<?php echo base_url(); ?>index.php/admin/logout"><i class="fa fa-sign-out"></i> <span>Logout</span></a></li>
</ul>
</section>
答案 1 :(得分:1)
&#34; if&#34;条件必须是这样的:
<?php if ($type == 'Employee' || $type == 'admin') { ?>
我也会改变&#34; {&#34; by&#34;:&#34;。这是一个例子:
<?php if ($type == 'Employee' || $type == 'admin'): ?>
<li><a href="<?php echo site_url(); ?>/admin/emp_requsition"><i class="fa fa-users"></i> <span>Employees Requsitions</span></a></li>
<?php endif; ?>
我认为更具可读性和清洁性,但这取决于您。
答案 2 :(得分:0)
像这样改变你的if条件
<?php if ($type == 'Employee' || $type == 'admin') { ?>