Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Extending Validation class
  • Hi, I've extended Validation class . I created Myvalidation class under app/classes/myvalidation.php. My code is given below. class Myvalidation extends Validation {
    public static function _validation_dropdown($val) {
    return $val;
    }
    }
    Added this class to app/bootstrap.php. Autoloader::add_classes(array('Myvalidation' => APPPATH.'classes/myvalidation.php',));
    Then placed $val->add_callable('Myvalidation'); into my model class validate() function.
    To this same function, I called my extended validate function like $val->add_field('country_id', 'Country', 'required|dropdown'); Now when I run the code, I get the following error.
    Notice: Invalid rule "required/dropdown" passed to Validation, not used. in COREPATH/classes/validation.php [461]: _find_rule Can anyone please help ?
    Thanks in advance.
  • * moved to General. this is a question, not a tip/tutorial *
  • Oh, thanks for rectification :)
  • If the error refers to "required/dropdown" then you have specified your rules wrong. There is no slash separator in defining validation rules. And you should not extend core classes this way, FuelPHP isn't CodeIgniter. Either use "Validation extends \Fuel\Core\Validation" if you want your rules to be part of the validation class itself, or use a completely separated class for your rules (like app/classes/validationrules.php). Your way just creates a second copy of the Validation class that isn't used anywhere.
  • Thanks. Error fixed by using a separate class.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion