[eluser]Unknown[/eluser]
Hi there,
I am new to this lovely framework and I am trying to create a validator class for every controller for the seek of easy maintenance. For example, I have a category controller so I have a validator class as shown below for this conroller
Code:
class Category_validator extends Validator {
/**
* Class Constructor
*/
public function __construct() {
parent::__construct ();
}
/**
* Set the category validation rules
*/
public function set_rules($mode) {
$this->CI->form_validation->set_rules ( 'name', 'Category Name', 'trim|required|min_length[5]|max_length[70]|xss_clean' );
$this->CI->form_validation->set_rules ( 'active', 'Category Active', 'trim|required|callback_validate_active|xss_clean' );
}
/**
* Set error messages
*/
public function set_messages() {
# Set any custome form validation error messages over here
}
/**
* Runs the specified validation rules
* @param none
* @return none
*/
public function run($mode) {
return parent::run ( $mode );
}
/**
* Validate the value of category status
*
* @param string $value
* @return boolean
*/
public function validate_active($value) {
echo ' inside validation';
if (in_array ( $value, array ('Y', 'N' ) )) {
return true;
} else {
$this->CI->form_validation->set_message ( 'validate_active', 'The %s field can not have the value ' . $value . '' );
return false;
}
}
}
It is working fine but the call back function defined in the second validation rules never gets invoked. Am I doing something wrong? When I define the validate_Active method in the category controller. it works. Does this mean that call back function has to be in the controller and can not be defined somewhere else?
your usual support is highly appreciated