Welcome Guest, Not a member yet? Register   Sign In
Use a set_rules callback in a libraries
#4

You can extend CI_Form_validation and define new callbacks there.

Some notes about your implementation of MY_Form_validation.

You do not need to add the property $CI. The parent class CI_Form_validation already has that property and it is accessible in the extending class.
You don't need MY_Form_validation::__construct because it does not do anything besides call parent:: __construct. PHP will call the parent constructor without your help.
In the new callback you don't have to find the instance of form_validation because you're in the instance you're looking for.

All that said, your class should look like this.

PHP Code:
class MY_Form_validation extends CI_Form_validation
{
 
   function require_upload()
 
   {
 
       $this->set_message('require_upload'"Vous devez uploader une image");
 
       return false;
 
   }


As you stated, it would be used like this

PHP Code:
if($config_rules['images'] == true){ $this->form_validation->set_rules('images','images','require_upload');} 

Not sure why you have the callback always returning false. Maybe you're not done writing it yet?
Reply


Messages In This Thread
RE: Use a set_rules callback in a libraries - by dave friend - 11-28-2018, 04:43 PM



Theme © iAndrew 2016 - Forum software by © MyBB