CodeIgniter Forums
get user - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: get user (/showthread.php?tid=44328)



get user - El Forum - 08-11-2011

[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


get user - El Forum - 08-11-2011

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



get user - El Forum - 08-12-2011

[eluser]Mainboard[/eluser]
thanks