Rumah > pembangunan bahagian belakang > tutorial php > 登陆前后导航栏处理 2015-12-12,导航栏2015-12-12_PHP教程

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

WBOY
Lepaskan: 2016-07-12 09:03:23
asal
866 orang telah melayarinya

登陆前后导航栏处理 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>
Salin selepas log masuk

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>
Salin selepas log masuk

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>
Salin selepas log masuk

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1080771.htmlTechArticle登陆前后导航栏处理 2015-12-12,导航栏2015-12-12 注意:添加灰色背景处,关于ajax传值,和js的判断 1 登陆后控制器处理:判断是否登陆并传递...
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan