Welcome Guest, Not a member yet? Register   Sign In
Questions about dynamic routes
#1

[eluser]jabberjab[/eluser]
Hi there.

I'm quite far in the development process of a web application and I've come to the point that I'd like to begin constructing routes for the functionality.

I'd like the user to be able to browse a category in this URL form.

url.com/category .. There are a given set of categories, but they are dynamic in that they can be edited and they are stored in a database. Let me know if I am way off track here, but I'm guessing that I should query the table to see if the given "parameter" so to speak is valid and in the database, and then of course route to url.com/category/view/$1. And then try to route everything that's not a category to its default path.

The problem, however, is that I am unsure about how to do this code-wise. I am guessing I shouldn't insert database lookups in routes.php to achieve this.

Hope you can help me out Smile
#2

[eluser]TheFuzzy0ne[/eluser]
Is there any reason why you can't store your routes in a serialized array, and then save that array to a file? It should be simple enough to create an abstraction layer to for managing your routes dynamically.
#3

[eluser]bretticus[/eluser]
Unless you can depend on some convention for your categories, there's really no way I can think of to pull this off with the existing CI base code. However, you could have a rule that checks to see if the first three chars are "cat-" and route them to your category controller. Then again, I'm wondering why a URL like category/search/birds would cramp your style Wink

On a home-brewed MVC framework that I wrote recently (not CI) an SEO guy told me I had to stick geographic locations in my controller URI space. I accomplished this by tweaking my router class. That being said, you could always extend the CI Router.php class. If you do that, you can do what I did and use app caching to store the database categories in memory with a timeout (see APC or memcache.) I really hated the idea of smacking the database with a query every time for data that is fairly static.

EDIT: I stared answering and then walked away for a half hour so I didn't see Fuzzy's post. He makes a good point, there's nothing to stop you from using my app cache suggestion to dynamically build your route exceptions.
#4

[eluser]Phil Sturgeon[/eluser]
I plan on just replacing the PHP array with a very simple GUI for my CMS.

This will only take one extended method in Router.php. With a few keys on it and a bit of caching it will be fine.

Make libraries/MY_Router.php and add a function _set_routing(); Copy the current _set_routing() from the CI router and use it as base, then modify it.

Basically this method includes the PHP lib then loops through it. You just want to call a model, lib or method that will replace the PHP include with a db call. Let us know how it goes.




Theme © iAndrew 2016 - Forum software by © MyBB