我正在尝试使用 yii-booster 将自定义引导导航栏添加到我的网站。但是我没有使用 yii-booster api 来生成导航栏,而是使用了基本的引导框架方式。视觉效果很好,但由于某种原因,每次我尝试登录时,我都会显示我已登录,但Yii::app()->user->name
会是访客,当我刷新网站时,它会再次显示登录。
<div style="height: auto;" class="navbar-wrapper">
<div style="top: 0px;" class="navbar<?php if (!Globals::is_home_page()) echo ' navbar-fixed-top';?>" id="navigation">
<div class="navbar-inner">
<button type="button" class="btn btn-navbar collapsed" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="brand" href="<?php echo Yii::app()->request->baseUrl; ?>">mysite.com</a>
<div class="nav-collapse collapse">
<ul class="nav pull-right">
<li><a class="" href="<?php echo Yii::app()->request->baseUrl; ?>/#how">How It Works</a></li>
<?php
if (Yii::app()->user->isGuest)
{
echo '<li><a class="" href="'.Yii::app()->createUrl('/login').'">Login</a></li>';
}
else
{
echo '<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="javascript:void(0);">Profile <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="'.Yii::app()->createUrl('user').'">Profile</a></li>
<li><a href="'.Yii::app()->createUrl('/orders').'">Schedule</a></li>
<li class="divider"></li>
<li><a href="'.Yii::app()->user->logout().'">Logout ('.Yii::app()->user->isGuest.' '.Yii::app()->user->id.' '.Yii::app()->user->name.')</a></li>
</ul>
</li>';
}
?>
</ul>
</div>
</div>
</div>
</div>
但是当我使用下面的 yii-booster 时,它工作正常……我不太明白为什么我们必须使用 yii-booster 方式。因为 bootsrtap api 要容易得多。我对此很陌生,这里有什么我遗漏或不理解的吗?提前致谢...
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container-fluid">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="#"><?php echo Yii::app()->name ?></a>
<div class="nav-collapse">
<?php $this->widget('zii.widgets.CMenu',array(
'htmlOptions' => array( 'class' => 'nav' ),
'activeCssClass' => 'active',
'items'=>array(
array('label'=>'Contact', 'url'=>array('/site/contact')),
array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),
array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest)
),
)); ?>
</div>
</div>
</div>
</div>