Let’s say I have a view method that receives a variable via the URI.
ex. http://www.domain.com/item/view/200
Does it make sense to turn the incoming variable into the correct type? In this case, making $item_id into int which is what is expected.
For example, in the controller …
function view($item_id) {
if ( $this->item_model->checkItem( (int) $item_id )) {
...
}
}
Yeah, casting the variable as integer like you are doing is OK.
And the way to pass the segment into function is like