Welcome Guest, Not a member yet? Register   Sign In
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?




Theme © iAndrew 2016 - Forum software by © MyBB