Razvan Zamfir Razvan Zamfir - 3 years ago 178
PHP Question

Codeigniter 3: Undefined property: Controllername::$load

I am working on a Registration & Login system in CI3.

My controller is is made according to the CI user guide:

class Signin extends CI_Controller {

public function index()
{
$this->load->view('signin');
}

public function signin()
{
$this->form_validation->set_rules('email', 'Email', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run())
{
echo "You are in";
}
else
{
echo validation_errors();
}
}
}


I have loaded the libraries and helpers in autoload.php:

$autoload['libraries'] = array('database', 'form_validation', 'user_agent', 'session');

$autoload['helper'] = array('url', 'form');


Yet I get this error:

Message: Undefined property: Signin::$load
Filename: controllers/Signin.php


Why is this? Thank you!

Answer Source

You just need to add a constructor in your Signin controller.

class Signin extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        $this->load->view('signin');
    }

    public function signin()
    {  
        $this->form_validation->set_rules('email', 'Email', 'required');
        $this->form_validation->set_rules('password', 'Password', 'required');
        if ($this->form_validation->run())
        {
            echo "You are in";
        }
        else
        {
            echo validation_errors();
        }
    }
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download