Welcome Guest, Not a member yet? Register   Sign In
get user
#1

[eluser]Mainboard[/eluser]
hey everyone, i think that this is a noob question but im new with CI, so the only that i need is pass the id user in my model to my control because i have this
Model
Code:
function validate()
    {
    $this->default_db = $this->load->database('default', true);    
        
     $query = $this->default_db->select('*')->from('tb_membership')
    ->where('username', $this->input->post('username'))
    ->where('password', sha1($this->input->post('password')));

    $query = $this->default_db->get();
    /*
     foreach($query->result() as $row)
            {      
            $id = $row->id;
            }
    */
        return $query;
    }
Controll
Code:
function validate_credentials()
    {        
        $this->load->model('membership_model');
        $query = $this->membership_model->validate();
      
        if($query) // si las credenciales del usuario son validas...
        {    
          foreach($query->result() as $row)
            {      
            
            $data = array(
                'username' => $this->input->post('username'),
                    'id' => $row->id,
                'is_logged_in' => true);
            $this->session->set_userdata($data);
        
             }
             redirect('site/members_area');  
        }
    
        
        else // incorrect username or password
        {
            $this->index();
        }
    }
and works, but i have a problem with the else because doesn't works, i want to use the foreach in the model and only pass the $id to the controll so any idea, because i don't want to use the foreach in the controll and i think that the problem with the else is because i using the foreach
#2

[eluser]Frank Rocco[/eluser]
Code:
return $query->row(0);
#3

[eluser]Mainboard[/eluser]
thanks




Theme © iAndrew 2016 - Forum software by © MyBB