1

假设我有一个view通过 URI 接收变量的方法。

前任。http://www.domain.com/item/view/200

将传入的变量转换为正确的类型是否有意义?在这种情况下,制作$item_idint哪个是预期的。

例如,在控制器中...

function view($item_id) {
    if ( $this->item_model->checkItem( (int) $item_id )) {
    ...
    }
}
4

1 回答 1

1

是的,像你一样将变量转换为整数是可以的。

将段传递给函数的方式就像

$segment = $this->uri->segment(2); //get the second segmention
           // ^ You can send a default Values as well if itemid is not set
           // Like: $this -> uri -> segment(2, '0')
//now pass it to the function you need
于 2012-04-25T23:51:31.077 回答