CodeIgniter Forums
using the 1st segment of the url - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: using the 1st segment of the url (/showthread.php?tid=28441)



using the 1st segment of the url - El Forum - 03-11-2010

[eluser]xeroblast[/eluser]
we all know that the 1st segment of the URL is the controller name like "http://domain.com/controller/method/params"...

how can i make the 1st segment in the URL be a data of the controller?

i.e.

http://domain.com/foo

and in the controller

Code:
function index($bar=NULL) {
if ($bar) {
  echo $bar; // display 'foo'
} else {
  echo 'blah';
}
}



using the 1st segment of the url - El Forum - 03-11-2010

[eluser]GSV Sleeper Service[/eluser]
you could either set the default controller or set up a custom route. both are explained very well in the documentation.