echo user in view from sessions code igniter

前端 未结 3 1104
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-27 06:53

I am new in codeigniter. I have implemented a simple login system. I want to print out a username on my view page which is stored in sessions. here is my controller

<         


        
相关标签:
3条回答
  • 2021-01-27 07:38

    Just store the user name in the userdata (you've already done this!)

    $this->session->set_userdata('username') = 'John Doe';
    

    And retrieve it just like that

    $username = $this->session->userdata('username');
    
    0 讨论(0)
  • 2021-01-27 07:39

    controller file $data = array( 'username' => $result->name, );

    view file

               <?php echo $this->session->userdata('username')?> 
    
    0 讨论(0)
  • 2021-01-27 07:40
    $username = $this->session->userdata('username');
    
    //Pass it in an array to your view like
    $data['username']=$username;   
    $this->load->view('test',$data);
    
    //Then in you view you can display it as:
     echo $username;
    
    0 讨论(0)
提交回复
热议问题