0

Does anyone know if it's possible to use segments on the default controller?

For example if i want to go to a profile on my site, it would be site.com/profileName, i know you would use it to access other controllers but I want it work so that if codeigniter can't access any controllers by what is entered in the segment, then i'd like it to look for a matching profile name from a MySQL table and then access the correct profile page and if it fails to find a match then the page will not exist, anyone have any idea on how i'd go about doing this? thanks!

user1627990
  • 2,587
  • 2
  • 16
  • 18

2 Answers2

0

Your best bet is changing where the 404 error go, and catch things from there to either show 404 error, or show a profile page.

ahmad
  • 2,709
  • 1
  • 23
  • 27
0

What you need here is routes

open your application/config/routes.php

Youc could set (:any) like this

$route['(:any)'] = 'controller/method/$1';

here you can use the wildcard any. That if anything is entered it will direct to the controller you want it to be redirected the $1 holds the value of the segment you entered.

then on your method just do the usual query if exist or not do what you want.

tomexsans
  • 4,454
  • 4
  • 33
  • 49