CodeIgniter Forums
Method Argument Validation - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Method Argument Validation (/showthread.php?tid=45867)



Method Argument Validation - El Forum - 10-09-2011

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