Welcome Guest, Not a member yet? Register   Sign In
Undefined property
#1

[eluser]ibnclaudius[/eluser]
I'm getting this error when running a form, but I have no idea of why.

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined property: Site::$form_validation

Filename: controllers/site.php

Line Number: 28

Code:
public function login()
{
  $this->load->library('form_validation');
  
  if ($this->input->server('REQUEST_METHOD') === 'POST')
  {
   $this->load->helper('form');
  
   if ($this->input->post('action') === 'LOGIN')
   {
    $this->form_validation->set_rules('email', 'email', 'required');
    $this->form_validation->set_rules('password', 'password', 'required');
    
    if ($this->form_validation->run() !== FALSE)
    {
     $this->load->helper('email');
    
     if (valid_email($this->input->post('email')))
     {
      $this->load->library('encrypt');
      
      $data = array('email' => $this->input->post('email'),
        'password' => $this->encrypt->sha1($this->input->post('password'))
      );
      
      if ($this->mb_auth_lib->login($data))
      {
       redirect('usuario/mural', 'location');
      }
      else
      {
       $data['inexistent_login'] = TRUE;
      }
     }
     else
     {
      $data['invalid_email'] = TRUE;
     }
    }
   }
  }
  
  $data['title'] = 'MeuBoletim';
  $data['page'] = 'login';
  
  $this->load->view('layout', $data);
}
#2

[eluser]CroNiX[/eluser]
Is this a library or a controller?
#3

[eluser]ibnclaudius[/eluser]
controller
#4

[eluser]CroNiX[/eluser]
Post the whole controller. Are you sure line 28 is within your login method?
#5

[eluser]ibnclaudius[/eluser]
Code:
<?php

class Site extends CI_Controller
{
public function __construct()
{
  parent::__construct();
  
  $this->load->helper(array('url'));
  $this->load->library(array('mb_auth_lib', 'session'));
}

public function index()
{
  redirect('/site/entrar', 'location');
}

public function login()
{
  $this->load->library('form_validation');
  
  if ($this->input->server('REQUEST_METHOD') === 'POST')
  {
   $this->load->helper('form');
  
   if ($this->input->post('action') === 'LOGIN')
   {
    $this->form_validation->set_rules('email', 'email', 'required');
    $this->form_validation->set_rules('password', 'password', 'required');
    
    if ($this->form_validation->run() !== FALSE)
    {
     $this->load->helper('email');
    
     if (valid_email($this->input->post('email')))
     {
      $this->load->library('encrypt');
      
      $data = array('email' => $this->input->post('email'),
        'password' => $this->encrypt->sha1($this->input->post('password'))
      );
      
      if ($this->mb_auth_lib->login($data))
      {
       redirect('usuario/mural', 'location');
      }
      else
      {
       $data['inexistent_login'] = TRUE;
      }
     }
     else
     {
      $data['invalid_email'] = TRUE;
     }
    }
   }
  }
  
  $data['title'] = 'MeuBoletim';
  $data['page'] = 'login';
  
  $this->load->view('layout', $data);
}
}
#6

[eluser]ibnclaudius[/eluser]
I don't know why, but running in autoload works.

The error also occurs with:
Code:
$this->load->library('encrypt');

:SSS

Controller:
Code:
<?php

class Site extends CI_Controller
{
public function __construct()
{
  parent::__construct();
  
  $this->load->helper(array('url'));
  $this->load->library(array('mb_auth_lib', 'session'));
  
  $this->output->enable_profiler(true);
}

public function index()
{
  redirect('/entrar', 'location');
}

public function login()
{
  $this->load->library('form_validation');
  
  if ($this->input->server('REQUEST_METHOD') === 'POST')
  {
   $this->load->helper('form');
  
   if ($this->input->post('action') === 'LOGIN')
   {
    $this->form_validation->set_rules('email', 'email', 'required');
    $this->form_validation->set_rules('password', 'password', 'required');
    
    if ($this->form_validation->run() !== FALSE)
    {
     $this->load->library('encrypt');
      
     $data = array('email' => $this->input->post('email'),
       'password' => $this->encrypt->sha1($this->input->post('password'))
     );
    
     if ($this->mb_auth_lib->login($data))
     {
      redirect('usuario/mural', 'location');
     }
     else
     {
      $data['inexistent_login'] = TRUE;
     }
    }
   }
  }
  
  $data['title'] = 'MeuBoletim';
  $data['page'] = 'login';
  
  $this->load->view('layout', $data);
}
}/




Theme © iAndrew 2016 - Forum software by © MyBB