> 백엔드 개발 > PHP 튜토리얼 > 登陆前后导航栏处理 2015-12-12,导航栏2015-12-12_PHP教程

登陆前后导航栏处理 2015-12-12,导航栏2015-12-12_PHP教程

WBOY
풀어 주다: 2016-07-12 09:03:23
원래의
875명이 탐색했습니다.

登陆前后导航栏处理 2015-12-12,导航栏2015-12-12

注意:添加灰色背景处,关于ajax传值,和js的判断

1   登陆后控制器处理:判断是否登陆并传递用户信息   

<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 登陆前后主页导航栏的 登陆和未登录 的显示

<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 登陆后,js对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.htmlTechArticle登陆前后导航栏处理 2015-12-12,导航栏2015-12-12 注意:添加灰色背景处,关于ajax传值,和js的判断 1 登陆后控制器处理:判断是否登陆并传递...
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿