Welcome Guest, Not a member yet? Register   Sign In
Validation of variable given in path?
#1

[eluser]deed02392[/eluser]
I've got a validation routine for a certain ID, which basically checks it's valid in the database, which is fine when that is submitted in a form as I just use set_rules() against the _REQUEST name, but I'm not sure what the correct way to validate the ID is when it's given from path.

Eg:

/function/variable

function($var) {
//validate $var with rules in form_validation
}

I started without thinking to write $this->form_validation->set_rules(,
then I realised I have nothing to put for the name because of where it came from.
#2

[eluser]apodner[/eluser]
given a url of: "http://example.org/controllerFn/variable"

Code:
/* CONTROLLER */
public function controllerFn()
{
    $id = $this->uri->segment(2);
    $this->load->model('The_model');
    $valid = $this->The_model->validate_id($id);
    if ($valid == true) {
        /*DO SOMETHING FOR VALID IDs */
    } else {
        /*SOME ERROR FOR INVALID IDs
    }
}

/*MODEL*/
class The_model extend CI_Model
{
    public function __construct()
    {
        parent::__construct();
    }

    public function validate_id($id)
    {
        /* CODE TO VALIDATE ID THAT RETURNS
          * TRUE OR FALSE DEPENDING ON IF
          * ID IS VALID
          */

    }
}




Theme © iAndrew 2016 - Forum software by © MyBB