• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
display error by function

#1
hi in my model i have this function :

Code:
    function login($email,$passwrd){
       
       $this->db->where('email', $email);
       $q = $this->db->get('users')->row();
       
       if($q->num_rows()!=0){
           if ($q->password_hash==$passwrd){
               $_SESSION['user_id']=$q->id;
           } else {
               $errors[]='Password error'  ;
         
           }
       }
       else{
           $errors[]='Username error'  ;
       }
       

       
    }
     


HOw can i show error in view ?
Reply

#2
return the errors array. Then you can add it to your view like so: $this->load->view('your-view', ['errors' => $errors]);
Simpler is always better
Reply

#3
(06-15-2017, 05:59 PM)donpwinston Wrote: return the errors array. Then you can add it to your view like so: $this->load->view('your-view', ['errors' => $errors]);

This is my function on controller (simple function only to try):

Code:
public function index(){
       $this->load->library('form_validation');
       $this->form_validation->set_rules('email','email','required|valid_email', array('required' => 'Inserisci la mail','valid_email'=>'la mail deve essere valida'));
       $this->form_validation->set_rules('password','password','required|min_length[6]');
       
       if($this->form_validation->run()){
           
          $this->load->model('user_model');
         
          $res=$this->user_model
          ->login(
              $this->input->post('email'),
              $this->input->post('passwrd')
           );
         
          if($res!=false){
             $_SESSION['user_id']=$res->id;
          }
         
       }
       
       
       $this->load->view('user/login',['errors' => $errors]);
   }
   


But in my view i have :

A PHP Error was encountered
Severity: Notice
Message: Undefined variable: errors
Filename: controllers/User.php
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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