douya6606 2016-11-04 18:05
浏览 38
已采纳

使用codeigniter在导航栏中显示配置文件图像

I am trying to show user image in navbar top section like Username "Image" just like in this site or any other.

This is what i try.

View

 <li class="">
                    <a href="#" class="user-profile dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                        <img src="<?php echo base_url(); ?>profileimages/<?php if (isset($_SESSION['Prof']))
                        {
                            echo $_SESSION['Prof'];
                        }?>" alt=""><?php echo $admin;?>
                        <span class=" fa fa-angle-down"></span>
                    </a>
                    <ul class="dropdown-menu dropdown-usermenu pull-right">
                        <li><a href="Profile"> Profile</a></li>
                        <li><a href="Profile_Setting"> Setting</a></li>
                        <li><a href="logout"><i class="fa fa-sign-out pull-right"></i> Log Out</a></li>
                    </ul>
                </li>

I am putting the image in session in login model,

Model

public function login_admin($username,$password)
    {
        $query=$this->db->where(['Username'=>$username,'Password'=>$password])->get('dc_admin');
        if($query->num_rows()>0)
        {
            foreach ($query->result() as $row)
            {
                $q=$row->Profile_Picture;
                $_SESSION['Prof']=$q;
            }

            $this->session->set_userdata('logged_in',$username);
            redirect('Master/Users');
        }
        else
        {
            redirect('Master');
        }

    }

I am new in CI and try to learn, please tell what i can do here to get image, i am able to get the logged IN username but not the image.

Any help will be appreciated.

  • 写回答

2条回答 默认 最新

  • dongliang1996 2016-11-20 20:24
    关注

    I just make a simple change in my code, and follow the session idea by the above Answers. The below code fixed my issue.

     public function login_admin($username,$password)
    {
        $query=$this->db->where(['Username'=>$username,'Password'=>$password])->get('dc_admin');
        //this is for single record
    
        if($query->num_rows()>0)
        {
            $rw = $query->row();
            $q = $rw->Profile_Image;
            $this->session->set_userdata('prfimg', $q);
            $this->session->set_userdata('logged_in',$username);
            redirect('Master/Users');
        }
        else
        {
            redirect('Master');
        }
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 帮我做下照片上的PLC题
  • ¥15 labview2022 使用modbus报缺少依赖?
  • ¥15 谷歌地图是不是不开通结算功能,api会使用不了哦
  • ¥15 unity腾讯云对象存储机型适配
  • ¥15 求全国交通咨询模拟代码,要求如下,可以完全在dev c++运行
  • ¥15 根据要求修改程序编码
  • ¥15 用 Python 做一个用 Excel 表导入的答题系统
  • ¥15 使用微信开发者工具实现一个“婚博会”小程序
  • ¥15 ros的rviz仿真机器人
  • ¥15 关于#linux#的问题(输入输出错误):出现这个界面接着我重新装系统,又让修电脑的师傅帮我扫描硬盘(没有问题)用着用着又卡死(相关搜索:固态硬盘)