[eluser]xwero[/eluser]
You can use the same does-it-exist approach that the controller and method use.
For database values i have written an abstracted method and put in a basemodel where all other models are children of.
Code:
function _exists($table,$value,$field = 'id')
{
$this->db->where($field,$value); // not chained for php4 compatibility and readability
return ($this->db->count_all_results($table) == 0)?FALSE:TRUE;
}
Now you have a very flexible function that can be used in any model with data shown in the url.
If the segment can only be a few values you extend the url helper with this function
Code:
function url_enum($segment,$redirect,$enum)
{
if( ! in_array($segment,$enum){ redirect($redirect); }
}
In your controller methods you can then do something like
Code:
function somepage()
{
$enum = array('ok','good','fine');
url_enum($this->uri->segment(3),'',$enum);
// is_rating is based on the _exists function
// is_rating parameter one is the position of the segment, for flexibility reasons
// the second parameter is for the same reason as in the url_enum function, to redirect the page
$this->somemodel->is_rating(4,$this->uri->segment(3));
}
These two helpers will validate almost all parameter segments.