• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Method Argument Validation

#1
[eluser]ranjudsokomora[/eluser]
Good Day Fellow CI Followers,
I wanted to gather some thoughts on method argument validations. Here is my example method:

Code:
function page($pageID="",$segment="index") {
    IF (EMPTY($pageID)) {
        return FALSE;
    }
    IF (!is_numeric($pageID)) {
        return FALSE;
    }
    /*
      What ever logic here
    */
}

I was thinking about building a method validation class that would almost be an extension of the CI Form validation class. So the above code would look something like this:

Code:
function page($pageID="",$segment="index") {
    $this->method_validation->set_rules($pageID,"required|numeric");
    $this->method_validation->set_rules($segment,"required");
    IF ($this->method_validation->run()===FALSE) {
        return FALSE;
    }
    ELSE {
        /*
            What ever logic here
        */
    }
}

My first concern would be how to handle callbacks, since the only way (that I know of) to find the 'calling' class is to use debug_backtrace, which seems a waste of time to me...


Any thoughts or suggestions?


Messages In This Thread
Method Argument Validation - by El Forum - 10-09-2011, 05:44 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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