CodeIgniter Forums

Full Version: Method Argument Validation
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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?