• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extended Validation library won't work.

#1
[eluser]patbert[/eluser]
I added a few functions to the Validation library:

http://pastebin.com/m4f347558

Those functions work perfectly if I keep them in my controller and use something like:
$rules['name'] = "callback_checkname|required|min_length[3]|max_length[30]";

But when I use my validation library and remove the callback_ part they fail to work.

The file I created is called my_validation.php and as far as I can tell it is loaded ok.

What am I doing wrong here?

#2
[eluser]wiredesignz[/eluser]
You are using $this->auth->check inside the validation class is one issue.

#3
[eluser]xwero[/eluser]
If you extend the Validation library you have to check if the class and the model are known. As a part of my validation overwrite i added a model_check which has this code
Code:
function model_check($field,$param)
    {
        if($this->_stand_alone)
        {
            $param = $this->_to_array($param);
        }
        list($model,$method) = $param;
        $args = false;
        if(count($param)>2)
        {
            $param = array_slice($param,2);
            $args = true;
        }
        // begin importance for patbert
        if(!class_exists($model))
        {
            $this->_set_message('model_class_not_found',$model);
            return 2;
        }
        
        $methods = get_class_methods($model);
        if(!in_array($method,$methods))
        {
            $this->_set_message('model_method_not_found',$method);
            return 2;
        }
        
        $error = '';
        if($args)
        {
            $error = call_user_func(array($model, $method),$param);
        }
        else
        {
            $error = call_user_func(array($model, $method));
        }
        // end importance for patbert
        if($error != '')
        {
            if(is_array($error))
            {
                foreach($error as $err)
                {
                    $this->_set_message($err,$field);
                }
                
            }
            elseif(strlen($error)>1)
            {
                $this->_set_message($error,$field);    
            }
        }
    }
This is an example of a check for a loaded library, it doesn't have to be a model, but i'm planning to extend the method to load the library if present.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.