Problems using session + validation on CodeIgniter

2019-06-12 19:40发布

问题:

Im working on CodeIgniter Framework. I used the library session without problems, getting data like this $this->session->usserdata('IdUsuario') this is ok.

But after uses form_validation :

  public function verify_password()
    {
      $this->load->library('form_validation');

            $this->form_validation->set_rules('Password', 'Contraseña', 'required|trim|callback_correct_password');
            $this->form_validation->set_rules('Password1', 'Nueva ontraseña', 'required|trim');
            $this->form_validation->set_rules('Password2', 'Repetir contraseña', 'required|trim|matches[Password1]');

            $this->form_validation->set_message('correct_password', 'Contraseña incorrecta');
            $this->form_validation->set_message('required', 'El campo %s es obligatorio.');
            $this->form_validation->set_message('matches', 'El campo %s no es igual que el campo %s.');
            if ($this->form_validation->run() == FALSE) {
                $this->edit_password();
            } else {
                   $this->Opciones_model->save_password($this->input->post('Password'), $this->session->usserdata('IdUsuario'));
                   $this->index();
            }
    }

I get every time:

Fatal error: Call to undefined method CI_Session::usserdata()

This happens only when I use validation + session, I tried few differents tries but always the same error.

Session is defined on autoload file (Its working).

回答1:

Try this:

 $this->session->userdata('IdUsuario')

Instead off,

 $this->session->usserdata('IdUsuario')