0

这是我的方法

public function sale($id,$type){
   if($id==TRUE){
       .....................
       .....................
    }
    if($type==TRUE){
      .......................
      .......................
    }
}

我想单独浏览两个参数,假设

http://mysite.com/mycontroller/sale/id

http://mysite.com/mycontroller/sale/type

怎么可能

4

2 回答 2

1

试试这个:
URL 格式: http: //mysite.com/mycontroller/sale/id(不可能)
现在:http: //mysite.com/mycontroller/sale/selector/id/value/1
现在:http:// mysite.com/mycontroller/sale/selector/type/value/1

function sale(){
   $type    = $this->uri->segment(4);  #get the selector
   $val     = $this->uri->segment(6);  #get the value
   if( $type == "id" ){
        #in id selection
   }else if( $type == "type" ){
      #in type selection
   }else{
        redirect('somewhere', 'refresh');
   }
}
于 2013-09-09T08:58:34.443 回答
0

您可以使用 URL 传递多参数:

例如以下网址:

http://mysite.com/mycontroller/sale

http://mysite.com/mycontroller/sale/3

http://mysite.com/mycontroller/sale/3/computer

这里代码:

public function sale($id = false, $type = false) {

   if($id) {
       // something to do
   }

   if($type) {
      // something to do
   }
}
于 2013-09-09T09:15:41.037 回答