zoukankan      html  css  js  c++  java
  • 登陆前后导航栏处理 2015-12-12

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

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

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

    2   登陆前后主页导航栏的 登陆和未登录 的显示

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

    3   登陆后,js对box的操作

    <script>
    $(function () {/*控制导航栏显示登陆还是个人中心*/ $.post("{:U('user/index/is_login')}",{},function(data){ if(data.status==1){ if(data.user.avatar){ $("#main-menu-user ul li .headicong").attr("src",data.user.avatar.indexOf("http")==0?data.user.avatar:"__UPLOAD__avatar/"+data.user.avatar); } $("#main-menu-user ul li .user-nicename").text(data.user.user_nicename!=""?data.user.user_nicename:data.user.user_login); $("#main-menu-user .userlogin").show(); $("#main-menu-user .userout").hide(); } if(data.status==0){ $("#main-menu-user .userout").show(); $("#main-menu-user .userlogin").hide(); } }); }); </script>
  • 相关阅读:
    canvas gamebricks
    javascript 判断对象的值是否相等
    让控件全屏显示(WinForm)
    网络视频监控
    回调函数
    [导入][链接]FreeBSD + Sun Java
    [导入][一点一滴学英语]20060330
    [导入][来自网络] 酸酸甜甜就是我 不用我多介绍了 可是你是否听过天津话的版本?
    [导入][链接]差点漏掉 Eclipse 3.2 M6出来了
    [导入][链接]Five reasons why you should never use PostgreSQL
  • 原文地址:https://www.cnblogs.com/jingzi111/p/5041551.html
Copyright © 2011-2022 走看看