Search code examples
phpcodeignitercodeigniter-urlcodeigniter-routing

manage controlller's method parameter in codeIgniter


Here my method

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

I want Browse two parameter individually, suppose

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

and

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

How can it possible


Solution

  • Try this:
    URL Format : http://mysite.com/mycontroller/sale/id ( not possible )
    NOW : http://mysite.com/mycontroller/sale/selector/id/value/1
    NOW : 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');
       }
    }