很抱歉,如果这个问题对你很愚蠢,但似乎我无法理解。我有两个函数isLogged
和isAdmin
。它们完美地工作并基于它们我想在我的导航栏上创建链接。我正在尝试的是这个
<li>Non Logged users link visible for everyone visiting the site</li>
@if(isLoggedIn() && !isAdmin())
<li>LoggedIn Link</li>
@if(isLoggedIn() || isAdmin())
<li><a href="">Both</a></li>
@endif
<li><a href="#">Logged In link</a></li>
@elseif(isAdmin())
<li><a href="#">Admin Dashboard</a></li>
@else
<li><a href="#">Login</a></li>
@endif
基本上我想在这里创建的是
users
admins
都不是users
,但有一些链接对管理员不可见。 admins
users
都有不同的链接,只有他们可以看到。admins
无论<li><a href="">Both</a></li>
还是普通用户都有其链接的附加链接。@if - &gt; (BaseController :: isLoggedIn()&amp;&amp;!BaseController :: isAdmin())检查用户是否已登录但不是admin
然后在里面我已经放置了另一个应该在Admins
上显示User
的用户和用户,因为他们已登录...但我只在登录Admin
时看到此链接。在div{
max-width: 500px;
background: #f4f7f8;
padding: 20px;
background: #f4f7f8;
border-radius: 8px;
font-family: Georgia,"Times New Roman",Times,serif;
}
form{
display: inline-block;
}
.form-style-5{
max-width: 250px;
background: #f4f7f8;
padding: 20px;
background: #f4f7f8;
border-radius: 8px;
font-family: Georgia,"Times New Roman",Times,serif;
margin: 0 auto;
}
.form-style-5 fieldset{
max-width: 500px;
background: #f4f7f8;
padding: 0;
background: #f4f7f8;
border-radius: 8px;
font-family: Georgia,"Times New Roman",Times,serif;
border: none;
}
.form-style-5 legend {
font-size: 1.4em;
margin-bottom: 10px;
text-align: center;
color: #717171;
border: 0;
}
.form-style-5 label {
display: block;
margin-bottom: 8px;
}
.form-style-5 input[type="text"],
.form-style-5 input[type="number"]{
font-family: Georgia, "Times New Roman", Times, serif;
background: rgba(255,255,255,.1);
border: none;
border-radius: 4px;
font-size: 16px;
margin: 0;
outline: 0;
padding: 7px;
width: 100%;
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
background-color: #e8eeef;
color:#8a97a0;
-webkit-box-shadow: 0 1px 0 rgba(0,0,0,0.03) inset;
box-shadow: 0 1px 0 rgba(0,0,0,0.03) inset;
margin-bottom: 30px;
}
.form-style-5 input[type="text"]:focus,
.form-style-5 input[type="number"]:focus
{
background: #d2d9dd;
/*outline: none;
border-color: #9ecaed;
box-shadow: 0 0 10px #9ecaed;*/
background: #1abc9c;
color: #fff;
height: 30px;
width: 30px;
display: inline-block;
font-size: 0.8em;
margin-right: 4px;
line-height: 30px;
text-align: center;
text-shadow: 0 1px 0 rgba(255,255,255,0.2);
border-radius: 15px 15px 15px 0px;
}
.form-style-5 select{
/*Removing this name selector causes the below button class selector CSS to not be applied?*/
}
.form-style-5 input[type="submit"],
.form-style-5 input[type="button"]
{
position: relative;
display: block;
padding: 19px 39px 18px 39px;
color: #FFF;
margin: 0 auto;
background: #1abc9c;
font-size: 18px;
text-align: center;
font-style: normal;
width: 100%;
border: 1px solid #16a085;
border-width: 1px 1px 3px;
margin-bottom: 10px;
}
.form-style-5 input[type="submit"]:hover,
.form-style-5 input[type="button"]:hover
{
background: #109177;
}
上不可见。
我知道ACL,但我真的不需要acl。我想用这样的条件来完成这个。
如何构建条件?
答案 0 :(得分:1)
@if(isLoggedIn() || isAdmin())
<li><a href="">Both</a></li>
@endif
把它放在底部
@if(isLoggedIn() && !isAdmin())
阻止它显示
编辑:试试这个
@if(isLoggedIn() && !isAdmin())
<li>LoggedIn Link</li>
@endif
@if(isLoggedIn() || isAdmin())
<li><a href="">Both</a></li>
@endif
@if(isAdmin())
<li><a href="#">Admin Dashboard</a></li>
@else
<li><a href="#">Login</a></li>
@endif
答案 1 :(得分:1)
假设你的两个辅助函数正常工作,这样的东西会更干净,工作得更好......
@if(isLoggedIn())
// HTML for all logged in users
@if(isAdmin())
// HTML for admins only
@else
// HTML for non-admins only
@endif
@endif