How to store variable in session codeigniter

前端 未结 4 864
情歌与酒
情歌与酒 2021-01-05 17:10

I would like to store the variable in the session currently i am tryin like this but not working.

In Controller



        
4条回答
  •  花落未央
    2021-01-05 17:36

    I consider storing my session data in a controller. So this is how you should go about storing and retrieving session data

    1.Use autoload in your config.php files. It saves you time and load time

    autoload['libraries'] = ('session);

    2.In your controller.php create an array to store your session data.

    $new_data = array( 'username' => 'martin', 'email' => 'someone@martin.com', 'user_logged => TRUE );

    $this->session->set_userdata($new_data);

    1. Then this is how to call your session data(create a variable and assign it the value of one of the session data you need):

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

    For further reference visit codeigniter user_guide/sessions

提交回复
热议问题