CodeIgniter Forums
How to do that? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: How to do that? (/showthread.php?tid=29627)



How to do that? - El Forum - 04-15-2010

[eluser]7amza[/eluser]
hey dears ,
i use routes library to rewrite urls :
$route['(:any)-(:num)'] = "category/Select/$1/$2";
so the url will be like that :
base_url/Politic-3
but when i request : $this->uri->segment(2)
i get Politic-3 but i want get just Politic and if i request : $this->uri->segment(3) i will get 3
so can i do that?
//sorry for my bad english .


How to do that? - El Forum - 04-15-2010

[eluser]Twisted1919[/eluser]
If i were you , i wouldn't use routes .
I would create a function called select() and i would do like :
Code:
function select($uri=''){

if( preg_match('/([a-zA-Z0-9]+)-([0-9]+)/ix',$uri,$matches) ){
   $first = $matches[0];//politic
   $second= $matches[2];//3
}

}

or you can do it easier :
Code:
function select(uri=''){
  if( strpos($uri,'-') !== false ){
    $u = explode('-',$uri);
    $first = $u[0];//politic
    $second= $u[1];//3
  }
}

Don't use routes when you don't really need them .