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条)

报告相同问题?