Search code examples
phpcodeignitervalidationautoloader

form_validation class does not load (codeigniter)


My script fails to load form_validation class.

I called it from autoload.php, controller's _construct method and the method i was intend to use (ie. login() method)

autoload.php

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

controller

<?php
class Login extends CI_Controller
{
function __construct()
{
    parent::__construct();
    $this->load->model('user_model');
    $this->load->library('form_validation');
}

function logmein()
{       
    $this->load->library('form_validation');
    $this->form_validation->set_rules('userEmail', 'email', 'trim|required|valid_email|callback__check_login');
    $this->form_validation->set_rules('userPassword', 'password', 'trim|required');

please do note that, i did not try to load the class from all the three places, i tried each one solely, and the combinations, but no success. I'm running PHP Version 5.3.5 on my localhost with XAMPP on windows 7. My real server is linux so if it works well on linux, i can live with that =)

update: i have var_dumped and checked the resources, and both _user_model_ and _form_validation_ seem to work well. however, when i var_dump($this->user_model) or var_dump($this->form_validation) returns NULL.


Solution

  • All of my code was actually error-less.

    However in one of my library classes, i have extended a controller class to load another library which was causing all of my errors.

    I have removed it and used $CI =& get_instance(); method for loading other classes and everything works fine now.