Welcome Guest, Not a member yet? Register   Sign In
Permalink type structure on top of other controllers
#1

[eluser]ChangedNames[/eluser]
I'm trying to build an application that will have multiple pages of data stored in the database that would have corresponding permalinks and have the URI use those links instead of IDs in the database. It's very easy to do something like have a controller called "page" and pull up the info via www.mysite.com/page/my_permalink_name/

What I am interested in doing is somehow (maybe with routing?) have the database look at the URI first for a permalink match and THEN if there isn't a permalink in the database look for a controller that goes with the address.

Does this make any sense? Any thoughts? I couldn't really figure out how to search the forums for this so if there is already something around regarding the topic just link me over and I'll read through it.

Thanks Smile
#2

[eluser]ChangedNames[/eluser]
After thinking a bit more on this I came up with this:

I can route any URI to a specific page initially and within the index function of that controller process the permalink in the database or produce an error page.

Code:
$route['default_controller'] = "pages";
$route['([a-zA-Z0-9-_]+)'] = "pages/$1";

Then for each application specific controller I can add another route for that specific controller to ensure it superceeds the prior "pages" route thus producing this in my routes:

Code:
$route['default_controller'] = "pages";
$route['([a-zA-Z0-9-_]+)'] = "pages/$1";
$route['photos'] = "photos";
$route['add_article'] = "add_article";
$route['etc'] = "etc";

What do you think of this approach? Is there a better way to do it? I would not be surprised if there is one.




Theme © iAndrew 2016 - Forum software by © MyBB