Thomas Clowes
Thomas Clowes

Reputation: 4609

Codeigniter extend library NOT working. No reason

<?php
class MY_Form_validation extends CI_Form_validation {

    function My_Form_validation()
    {
        parent::CI_Form_validation();
    }

}  

This is the code in the file MY_Form_validation.php that I have created in my CI libraries folder. There were some functions in there but i removed them to try and get to the bottom of this.

Utilizing this library extension, form validation simply does not work at all. I have all my form validation rules in a config file.

If i delete MY_Form_validation.php everything works perfectly.

A post on the CodeIgniter board yielded no results.

Perhaps someone here could help? Thanks

Upvotes: 1

Views: 5318

Answers (4)

Silambarasan R
Silambarasan R

Reputation: 1556

As I'm using CI 3 Form validation, the following is working for me.

class MY_Form_validation extends CI_Form_validation {

    public function __construct( $rules = array() )
    {
        parent::__construct($rules);
    }

    //other validation functions...
}

Happy Coding

Upvotes: 0

Sandeep Sherpur
Sandeep Sherpur

Reputation: 2802

Make file name in your application/library directory: MY_Form_validation.php

then in your class

Code:

class MY_Form_validation extends CI_Form_validation

{
 function My_Form_validation()
   {
       parent::CI_Form_validation();
   }

}

Upvotes: 1

dmulvi
dmulvi

Reputation: 639

In case you've upgraded to CodeIgniter 2.0.x or later make sure that you change the above code to:

class MY_Form_validation extends CI_Form_validation {

function MY_Form_validation( $config = array() )
{
    parent::__construct($config);
}

Notice the change from:

parent::CI_Form_validation($config);

To:

parent::__construct($config);

Definitely caused me a problem for a bit!

Upvotes: 3

rkj
rkj

Reputation: 566

Try this instead. You need to pass the $config array from the extended class to the CI_Form_validation. Also make sure the spelling is correct and case sensitive.

class MY_Form_validation extends CI_Form_validation {

    function MY_Form_validation( $config = array() )
    {
        parent::CI_Form_validation($config);
    }

Upvotes: 5

Related Questions