Welcome Guest, Not a member yet? Register   Sign In
Session data
#1

[eluser]triplewhat[/eluser]
How do I add information from the database to the session? I am new and trying to learn this. Sorry

I have a model with this info
Code:
function validate()
{
  $this->db->select('username', 'password', 'title');
  $this->db->where('username', $this->input->post('username'));
  $this->db->where('password', $this->input->post('password'));
  $query = $this->db->get('users');
  
  if($query->num_rows == 1)
  {

   return $query;
  }
  
}



And then a controller with this

Code:
public function validate_credentials(){  
  $this->load->model('membership_model');
  $query = $this->membership_model->validate();
  
   if($query) // if the user's credentials validated...
  
   {

    $data = array(
     'username' => $this->input->post('username'),
     'logged_in' => true
    );

    $this->session->set_userdata($data);
    $data['main_content'] = 'home';
    $data['page_title'] = 'title';
    $this->load->view('includes/template', $data);
   }else{  // incorrect username or password
    $this->index();
   }
  }

I am trying to add title to the session
#2

[eluser]InsiteFX[/eluser]
Code:
$data = array(
     'title'     => 'Your Title',
     'username'  => $this->input->post('username'),
     'logged_in' => true
);

// or
$this->session->set_userdata('title', 'your_title');
#3

[eluser]triplewhat[/eluser]
I don't want to set the title there, i want to pull it from the database. It is already set there. The menu will changed based on the users title
#4

[eluser]InsiteFX[/eluser]
Well put it from your database and set it thats how you do it!
#5

[eluser]triplewhat[/eluser]
Its in my database I dont know how to select it, or how to call it, please don't answer me like that. I need examples
#6

[eluser]triplewhat[/eluser]
I selected it in the model, how to i retrieve it in the controller, or is that the wrong way. I need examples please.
#7

[eluser]Ajaxboy[/eluser]
Did you already went through the docs? http://ellislab.com/codeigniter/user-gui...sions.html
#8

[eluser]triplewhat[/eluser]
yes. I dont understand how to get the value of title into an array to add to session data
#9

[eluser]triplewhat[/eluser]
[quote author="InsiteFX" date="1335065627"]Well put it from your database and set it thats how you do it!
[/quote]

And how exactly do I do that Smile
#10

[eluser]Ajaxboy[/eluser]
I created my own session class so I am not making use of the CI session class..

but my understanding is that to get data you would do this:

$this->session->userdata('title');
$this->session->userdata('username');
$this->session->userdata('logged_in');




Theme © iAndrew 2016 - Forum software by © MyBB