Welcome Guest, Not a member yet? Register   Sign In
display error by function
#3

(06-15-2017, 04: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


Messages In This Thread
display error by function - by pippuccio76 - 06-15-2017, 02:45 PM
RE: display error by function - by donpwinston - 06-15-2017, 04:59 PM
RE: display error by function - by pippuccio76 - 06-16-2017, 04:10 AM



Theme © iAndrew 2016 - Forum software by © MyBB