Home >Backend Development >PHP Tutorial >Navigation bar processing before and after login 2015-12-12, navigation bar 2015-12-12_PHP tutorial

Navigation bar processing before and after login 2015-12-12, navigation bar 2015-12-12_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-12 09:03:23896browse

Navigation bar processing before and after login 2015-12-12, navigation bar 2015-12-12

Note: add gray background, about ajax value transfer, and js Judgment

1 Controller processing after login: determine whether to log in and transfer user information

<span>class</span> IndexController <span>extends</span><span> HomeBaseController {
    </span><span>//</span><span>登录</span>
    <span>public</span> <span>function</span><span> index() {
        </span><span>$id</span>=I("get.id"<span>);      
        </span><span>$users_model</span>=M("Users"<span>);        
        </span><span>$user</span>=<span>$users_model</span>->where(<span>array</span>("id"=><span>$id</span>))-><span>find();      
        </span><span>if</span>(<span>empty</span>(<span>$user</span><span>)){
            </span><span>$this</span>->error("查无此人!"<span>);
        }
        </span><span>$this</span>->assign(<span>$user</span><span>);
        </span><span>$this</span>->display(":index"<span>);
    }
    </span><span>function</span><span> is_login(){
        </span><span>if</span><span>(sp_is_user_login()){
            </span><span><span>$this</span>->ajaxReturn(<span>array</span>("status"=>1,"user"=></span><span><span>sp_get_current_user()));</span>
        }</span><span>else</span><span>{
            </span><span>$this</span>->ajaxReturn(<span>array</span>("status"=>0,"info"=>"此用户未登录!"<span>));
        }
    }<br />。。。。。。</span>

2 Login and non-login display in the homepage navigation bar before and after login

<span><</span><span>div </span><span>id</span><span>="main-menu-user"</span><span>></span>
      <span><!--</span><span>还未登陆</span><span>--></span>
            <span><</span><span>div  </span><span>class</span><span>='userout </span><span>user' </span><span>></span>
                <span><</span><span>ul </span><span>class</span><span>="nav navbar-nav  navbar-right"</span><span>></span>
                    <span><</span><span>li</span><span>></span>
                        <span><</span><span>a </span><span>href</span><span>="{:u('user/register/index')}"</span><span> data-toggle</span><span>="dropdown"</span><span>></span>注册<span></</span><span>a</span><span>></span>
                    <span></</span><span>li</span><span>></span>
                <span></</span><span>ul</span><span>></span>
                <span><</span><span>ul </span><span>class</span><span>="nav navbar-nav  navbar-right"</span><span>></span>
                    <span><</span><span>li</span><span>></span>
                        <span><</span><span>a </span><span>href</span><span>="{:u('user/login/index')}"</span><span>  data-toggle</span><span>="dropdown"</span><span>></span>登陆<span></</span><span>a</span><span>></span>
                    <span></</span><span>li</span><span>></span>
                <span></</span><span>ul</span><span>></span>
                <span><</span><span>ul </span><span>class</span><span>="nav navbar-nav  navbar-right"</span><span> style</span><span>="margin-top:10px"</span><span>></span>
                    <span><</span><span>li </span><span>></span>
                        <span><</span><span>img </span><span>src</span><span>="__TMPL__/Public/img/headicon.png"</span><span> class</span><span>="headicon"</span><span>/></span>
                    <span></</span><span>li</span><span>></span>
                <span></</span><span>ul</span><span>></span>
            <span></</span><span>div</span><span>></span>
    <span><!--</span><span>已经登陆</span><span>--></span>
            <span><</span><span>div </span><span>class</span><span>="userlogin user"</span> <span>></span>
                <span><</span><span>ul </span><span>class</span><span>="nav navbar-nav  navbar-right"</span><span>></span>
                    <span><</span><span>li</span><span>></span>
                        <span><</span><span>a </span><span>href</span><span>="{:u('user/index/logout')}"</span><span> data-toggle</span><span>="dropdown"</span><span>></span>退出<span></</span><span>a</span><span>></span>
                    <span></</span><span>li</span><span>></span>
                <span></</span><span>ul</span><span>></span>
                <span><</span><span>ul </span><span>class</span><span>="nav navbar-nav  navbar-right"</span><span>></span>
                    <span><</span><span>li</span><span>></span>
                 <span><</span><span>a </span><span>href</span><span>="{:u('user/center/index')}"</span><span>  data-toggle</span><span>="dropdown"</span><span> class</span><span>="user-nicename"</span><span>></</span><span>a</span><span>></span>
                    <span></</span><span>li</span><span>></span>
                <span></</span><span>ul</span><span>></span>
                <span><</span><span>ul </span><span>class</span><span>="nav navbar-nav  navbar-right"</span><span> style</span><span>="margin-top:10px"</span><span>></span>
                    <span><</span><span>li </span><span>></span>
                        <span><</span><span>img </span><span>src</span><span>=""</span><span> class</span><span>="headicon"</span><span>/></span>
                    <span></</span><span>li</span><span>></span>
                <span></</span><span>ul</span><span>></span>
            <span></</span><span>div</span><span>></span>
<span></</span><span>div</span><span>></span>

3 After logging in, js operation on the box

<script><br /><span> $(</span><span>function</span><span> () {</span><span>/*</span><span>控制导航栏显示登陆还是个人中心</span><span>*/</span><span>
  $.post(</span>"{:U('user/index/is_login')}",{},<span>function</span><span>(data){
      </span><span>if</span>(data.status==1<span>){
          </span><span>if</span><span>(data.user.avatar){
<span>              $(</span></span><span>"#main-menu-user ul li .headicong").attr("src",data.user.avatar.indexOf("http")==0?data.user.avatar:"__UPLOAD__avatar/"+<span>data.user.avatar);
            }
      $(</span>"#main-menu-user ul li .user-nicename").text(data.user.user_nicename!=""?</span><span><span>data.user.user_nicename:data.user.user_login);</span>
      $(</span>"#main-menu-user .userlogin"<span>).show();
      $(</span>"#main-menu-user .userout"<span>).hide();               
      }
      </span><span>if</span>(data.status==0<span>){
         $(</span>"#main-menu-user .userout"<span>).show();
         $(</span>"#main-menu-user .userlogin"<span>).hide();
      }
});  });
</span></script>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1080771.htmlTechArticleNavigation bar processing before and after login 2015-12-12, navigation bar 2015-12-12 Note: Add gray background , about ajax value transfer, and js judgment 1. Controller processing after login: judge whether to log in and pass...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn