• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating a model for the login

#1
I am trying to learn codeigniter. I followed the Form Validation Example (https://codeigniter.com/userguide3/libra...ation.html).

I have manage to make it work but I would like to ask how would I include a model to validate the username and password in the DB and get the details.

Thanks
Reply

#2
you can use like this example in Model file.

PHP Code:
public function login($table,$email,$pass)
        {
            
$this->db->select("*");
            
$this->db->from($table);
            
$this->db->where('email',$email);
            
$this->db->where('pass',$pass);
            
$this->db->limit(1);
            
            
$query=$this->db->get();  // verileri getir
            
            
if($query->num_rows()==1){
                return 
$query->result();
            }else{
                return 
false;
            }
            
            
        } 

and u must change to application/config/autoload.php
$autoload['libraries'] = array('session','database'); 
like that. and make a sure true Config/database.php connect is right
and you must create controller like this
PHP Code:
public function login()
    {    
        
        
$email=$this->input->post("email");
        
$sifre=$this->input->post("pass");
        
         
$email=$this->security->xss_clean($email);
         
$sifre=$this->security->xss_clean($pass);
         
$this->load->model('Database_Model');
        
        
$result$this->Database_Model->login("Admin",$email,$pass); //1. Db in
        
        
if($result)
        {
 
                   $sess_array = array(
 
                       
                        
'id' => $result[0]->Id,
 
                       'email' => $result[0]->email,
 
                       'pass' => $result[0]->pass,
 
                       
                    
);

 
                    $this->session->set_userdata("admin_session",$sess_array);
 
                    redirect(base_url().'admin/home');        
                  
                        
                    
                



i think its gonna be help to u.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.