dongmopu6734 2015-01-18 02:30
浏览 51
已采纳

我如何从codeigniter回显我的会话数组

I know this question has been asked before but my session array is set up different and i would liuke to be able to echo out 'firstname', and 'email' in my members view.

Here is what my session array looks like:

Array
(
    [session_id] => 0be663ae77530e5992d3116af24a216d
    [ip_address] => 
    [user_agent] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36
    [last_activity] => 1421547754
    [user_data] => 
    [email] => Array
        (
            [firstname] => Travis
            [email] => theller5567@gmail.com
            [password] => 894027e71b85d60bcc5b0dbe6e83f1f6
        )

    [is_logged_in] => 1
    [firstname] => 
)

I want to get to the email array and echo out the firstname. any help would be greatly appreciated, thank you.

this is my function that sets the userdata. if you see a better way of doing it please by all means share, i would be very greatfull. public function register_user($key){

$this->load->model('model_users');
        if($this->model_users->is_key_valid($key)){
            if($newemail = $this->model_users->add_user($key)){
                $data = array(
                    'firstname' => $this->input->post('firstname'),
                    'email' =>  $newemail,
                    'is_logged_in' => 1
                );
                $this->session->set_userdata($data);
                redirect('login/members');
            }else echo "Failed to add user, please try again.";
        }else echo "invalid Key";
    }
  • 写回答

2条回答 默认 最新

  • dousongqiang2585 2015-01-18 02:35
    关注

    The easiest way I can think to access it would be this:

    $email = $this->session->userdata('email');
    

    Then you can echo the info inside of it with:

    echo $email['firstname'];
    

    and

    echo $email['email'];
    

    From what I can see, CodeIgniter's session library doesn't have any direct ways to access multidimensional array values.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?