Welcome Guest, Not a member yet? Register   Sign In
Login
#11

[eluser]Felipe Deitos[/eluser]
Hey CroNiX, can u answer me one more thing...

The login form is working and checking everything right...

What i wanna know: I got a menu in my header(view), when the visitor is not logged in he sees 3 itens, and when he is logged he sees 5 itens.

When the user log in, I set inside an array in the userdata:
Code:
'is_logged' => true

With that i can check if the usser "is_logged" or not...
I am doing like this in my header(view):
Code:
<?php if($this->session->userdata('is_logged')){ ?>
<p>Hidden Iten</p>
&lt;?php } ?&gt;

Is this the right way to do it, or there are best ways?




#12

[eluser]Felipe Deitos[/eluser]
Someonee? any idea?
#13

[eluser]CroNiX[/eluser]
It's basically what I do. If they are logged in, it shows links to their profile, etc, and if they aren't logged in it just shows the login form.
#14

[eluser]Felipe Deitos[/eluser]
Thanks for all your answers dude...
I am using that Template that you teached me...

I changed the way i validate de user, because i am storing the lvl(level) of the user in the session...
I dont know if what i am doing are the best pactices, but its working...

controller:
Code:
public function validate_user()
{
  $this->load->model('users_model');
  $data = $this->users_model->validate();
  
  if($data['is_logged'])
  {  
   $this->session->set_userdata($data);
   redirect($this->input->post('current_url'));
  }
  else
  {
   redirect($this->input->post('current_url'));
  }
}

model:
Code:
public function validate()
{
  $this->db->where('user', $this->input->post('user'));
  $this->db->where('password', md5($this->input->post('password')));
  $query = $this->db->get('users');
  
  // return ($query->num_rows == 1);
  
  if($query->num_rows == 1)
  {
   $data = array(
    'user' => $query->row('user'),
    'lvl' => $query->row('lvl'),
    'is_logged' => true
   );
   return ($data);
  }
  else
  {
   $data = array(
    'is_logged' => false
   );
   return ($data);
  }
}

The problem is... as you can see in the controller, if the 'is_logged' = false i just redirect the user to the current_url... i want to pass and error message with it... how can i do that using the Template style that you showed me?

Thanks again for all the help!
#15

[eluser]CroNiX[/eluser]
Look into session flashdata. You can set a message in your controller when they fail via flashdata just before you redirect, and then in your view check to see if it exists, and if it does, display it (the errors).
#16

[eluser]Felipe Deitos[/eluser]
This is great... really

Thanks mate!




Theme © iAndrew 2016 - Forum software by © MyBB