ID with slashes in Codeigniter route/controller

364 Views Asked by At

I have this route in Codeingniter

$route['([en|fr|es|it]+)/(.+)'] = 'My_Controller/index/$1/$2';

where first argument is a lang id and second is an unique iD. The ID has slashes in its format like:

item/34/public    
something/else
name/for/this/can/be/12345

Number of slashes in ID can be from 0 to (nobodyknows) so actually I´m getting the id in My-Controller with this hack :

public function index($lang,$id)
{
    $hack_id = $this->uri->segment(3);

    if ($this->uri->segment(4)) {
         $hack_id .= "/".$this->uri->segment(4);
    }

    if ($this->uri->segment(5)) {
        $hack_id .= "/".$this->uri->segment(5);
    }

    /*...and so go on if clauses, repeating and concatenating ...*/
    /* and finally passing the hack_id data to view */
}

It works, but I think it's a weird solution (I'm not really passing any id) and must be a way to do it better, a smarter solution (maybe in routes?).

Any help or clue are welcome...

0

There are 0 best solutions below