codeigniter和tank auth错误

时间:2013-12-26 04:49:56

标签: php codeigniter tankauth

您好我登录我的用户菜单时遇到问题。我试图在右侧得到它。当用户is_logged_in可以看到用户名和注销时,左侧仍然显示主页,论坛和联系人。但由于某些原因,当用户登录时仍显示注册并登录链接。我如何修复它我正在使用Tank_Auth和Codeigniter

<div class="navbar navbar-default" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"></a>
</div>
<div class="navbar-collapse collapse">
<?php if ($this->session->userdata('is_logged_in') != 1): ?>
<ul class="nav navbar-nav">
<li class="active"><a href="<?php echo base_url();?>">Home</a></li>
<li><a href="#">Forum</a></li>
<li><a href="#">Contact</a></li>
</ul>
<?php if ($this->session->userdata('is_logged_in') != 0): ?>
<?php endif; ?>
<ul class="nav navbar-nav navbar-right">
<li><a href="<?php echo base_url('auth/register');?>">Register</a></li>
<li><a href="<?php echo base_url('auth/login');?>">Sign In</a></li>
</ul>
<?php else: ?>
<ul class="nav navbar-nav navbar-right">

<li class="active"><a href=""><strong><?php echo $username; ?></strong></a></li>
<li><a href="<?php echo base_url('/auth/logout/'); ?>">Log Out</a></li>
<?php endif; ?>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>

1 个答案:

答案 0 :(得分:1)

在第二个ul之后放置<?php endif; ?>,如下所示

<?php if ($this->session->userdata('is_logged_in') != 0): ?>
    <ul class="nav navbar-nav navbar-right">
        <li><a href="<?php echo base_url('auth/register');?>">Register</a></li>
        <li><a href="<?php echo base_url('auth/login');?>">Sign In</a></li>
    </ul>
<?php endif; ?>

您正在使用Tank_Auth,因此您应该使用强制代码来检查用户登录

$this->tank_auth->is_logged_in()