using segments on default controllers in codeigniter to go to profiles after not finding the other controllers?

StackOverflow https://stackoverflow.com/questions/15734558

Question

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!

Était-ce utile?

La solution

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.

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top