Welcome Guest, Not a member yet? Register   Sign In
Dynamic Routing once again.
#1

[eluser]Unknown[/eluser]
Hello.

I would like to ask for a favor Smile Please direct me towards proper solution of dynamic routing for CMS-like app based on CI (and HMVC).

I can go without a code (i can write it), but actually I have vague idea HOW TO PLAN the algorithm (i guess my knowledge of CI inside logic is a bit too low).

Ok here's the situation.

I am writing quite simple CMS, based on CI (still 1.7.x) and HMVC.

I want user to be able to add different type of pages to the website, each of it being kind of "website objects". Adding the given type of page - provides some features for this page. It means when the user adds e.g. gallery-like page he gets all tools needed for it (adding images, sorting them, preparing order etc). If he makes blog entry - tools for blog. User can also set individual meta data, SEO attributes, etc. (something similar to what is done in PyroCMS). Each type is supported by one of the modules in the app both for admin purposes and serving the content later.

I use a bit non-typical DB structure, other then Pyre (and simmilar) CMSes. There is no "pages" table, nor "news" one, "blogs" etc. Website Objects - no matter what it really is (text page, gallery, page with photo, page with blog entry, etc) - are stored in one table, their features (real content for those pages or relations to other obiects) - in other. There is also nested sets table, where the whole app logical structure is stored.

Of course - each object has unique URI, no chances for the repeating it in the app.

My current routing is just static one. So I use links like

Code:
somedomain/gallery/website_object_individual_gallery_uri_here

and it goes for:

Code:
$route['gallery/(:any)'] = "gallery_module/controller/$1";


As I said - its simple idea, nothing strange till now.

But here my problem starts Smile


What I would like to achieve:

1. All pages in the website - all those "website objects" should be accessed like:

Code:
somedomain/website_obiect_uri_here


2. When the above URL is called there should be done:

a. connection to DB
b. check what kind of object is that 'website_object_uri_here'
c. routing to proper module/controller by dynamically constructed

Code:
$route['(:any)'] = "$proper_module/$controller_name/$1";

I have the static config, which provides array with info about what type of website object is "served" by what module. There arent so many types after all - so that config is enough.

What I would like to avoid:

Writing / caching static route for each created website object into a file after it is created.
Except of complications with writable config directories - my construction of objects can create thousands of objects (ie each comment, each image on page, especially if some of such pages are created automatically). And if thats not the big problem for to get the info about object from the DB - it can make problems for file-based reading.

I think that the simplest - and most dirty-hacking - solution is to include DB config into route.php, do the connection and the check, read types config array, and just route.

But - is it the only solution? Is it proper solution at all?

I know i could try .htaccess changes (to get rid of modules names in URLs) but I would like to code it into the app rather.

Should i try to make My_Route library instead, which will do the tests? But what to leave in route.php in such situation? Only default_controller?

Is this http://ellislab.com/forums/viewthread/121486/ thread the only other simple & clean solution?


Or maybe I just talk about something that should not be done at all Smile?

Any help with "search-knowledge-that-way" directions appreciated Smile




Theme © iAndrew 2016 - Forum software by © MyBB