Problems extending CodeIgniter libraries?

CodeIgniter (CI), an open source web application framework that helps you write kick-ass PHP programs, allows you to extend native CI libraries with your own freshly baked functionality.

I was having problems extending the form validation library, CI_Form_validation, while writing functions for generating forms using the validation rules set for CI_Form_validation. The validation rules can be set by using the function set_rules() directly in f.e. your controller. Also, rules can be saved as an array in a configuration file which is loaded while initializing CI_Form_validation. That way, you don’t have to pollute your controller with dozens of set_rules() calls or large arrays.

But, as soon as I’ve extended CI_Form_validation using:

class ci_extend_Form_Validation extends CI_Form_validation {
 
	function ci_extend_Form_Validation()
	{
		parent::CI_Form_validation();
	}
 
}

… the CI_Form_validation class stopped working (that’s what is looked like). After a forum post on the CI forums and some debugging I found the problem. From my forum post:

The loader class of CI checks for a corresponding config file when loading libraries. This is done at _ci_init_class() in CI_Loader. That all goes well, and the $config array defined at system/application/config/form_validation.php is passed to the extended class, NOT to CI_Form_validation.

So, we need to pass the $config array from our extended class to CI_Form_validation:

class ci_extend_Form_Validation extends CI_Form_validation {
 
	function ci_extend_Form_Validation($config)
	{
		parent::CI_Form_validation($config);
	}
 
}

Problem solved. Suggestions for more decent solutions are welcome!