0

am using ci 2.1.4 to create a simple crud application being new to ci and am having this error:'Unable to load the requested class: validation'
here is my controller code:

class Person extends CI_Controller{

    //num of records per page
    private $limit = 10;

    public function __construct(){
        parent::__construct();
        //load library
        $this->load->library(array('table','validation'));
        //load helper
        $this->load->helper('url');
        //load model
        $this->load->model('person_model','',TRUE);
    }

    function index($offset = 0){
        //offset
        $uri_segment = 3;
        $offset = $this->uri->segment(uri_segment);
        //load data
        $person = $this->person_model->get_paged_list($this->limit, $offset)->result();
        //generate pagination
        $this->load->library('pagination');
        $config['base_url'] = site_url('person/index/');
        $config['total_rows'] = $this->person_model->count-all();
        $config['per_page'] = $this->limit;
        $config['uri_segment'] = $uri_segment;
        $this->pagination->initialize($config);
        $data['pagination'] = $this->pagination->create_links();
        //generate table data
        $this->load->library('table');
        $this->table->set_empty(" ");
        $this->table->set_heading('No', 'Name', 'Date of Birth (dd-mm-yyyy)', 'Sex', 'Actions');
        $i = 0 + $offset;
        foreach ($persons as $person){
            $this->table->add_row(++$i, $person->name, strtoupper($person->sex)=='M'? 'Male':'Female', date('d-m-Y', strtotime($person->dob)),
            anchor('person/view/'.$person->id,'view',array('class'=>'view')).' '.   
            anchor('person/update/'.$person->id,'update',array('class'=>'update')).' '.
            anchor('person/delete/'.$person->id,'delete',array('class'=>'delete','onclick'=>"return confirm('Are you sure you want to delete this person?')"))
            );
        }
        $data['table'] = $this->table->generate();
        //load view
        $this->load->view('person_list', $data);
    }

Any idea what might be wrong?

4
Contributors
4
Replies
21
Views
3 Years
Discussion Span
Last Post by tapfumamanhanga
0

Hi,

The error says that library file is missing. I think 'validation' is not CI core library. I think you need 'form_validation'. So please try with 'form_validation' instead of 'validation'.

Please check and let me know.
Thanks,
Ajay

0

This has nothing to do with the controller code but the configurations in autoload.php. Go to the config folder and open autoload.php go the line where its written $autoload['libraries'] = array('.... then remove validation from the list and it work

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.