Welcome Guest, Not a member yet? Register   Sign In
Route using database information
#31

[eluser]easylancer[/eluser]
[quote author="n0xie" date="1242224681"][quote author="naldu" date="1242221594"]This is probably bad practice, but what about routing all requests to 1 controller that figures out whether the uri corresponds to a database record? If not, generate a 404.[/quote]
That's basically how our CMS works.

It 'hooks' into the standard CI and matches the url against a lookup table. Actually it matches against the cache, then matches against a lookup table.

The reasoning is simple: write once, read many. The big performance gain is that the hook initializes before any of the Database Class is loaded, which means it doesn't have to wait to establish a database connection. This way, if the page was already rendered, it reads directly from cache, just as a static html page would, which means a significant increase in speed.

If it doesn't match against the cache but matches against the lookup table, it loads a standard controller and passes the lookupId to it. where the CMS builds the page (loading models/plugins/template based on the lookupId) , writes it to cache, then outputs to the browser.

This will take care of about 70-90% of your 'standard' website where the only thing that changes is content.

This behaviour can be overwritten by adding a controller name to the lookup table in which case it loads that controller instead: this is to be avoided since it will result in 'obscure' routing and should be only done in case you have to hack the system. The preferred method works like this:

If the url does not match against either the cache or the lookup table, it processes the url as 'normal' trying to match it against a controller. This way when building a CMS you can build a 'contact' controller without having to code all sorts of exceptions. You would write it just the way you would any normal CI controller complete with form validation and some javascript 'bling'.

The pros of the system are:
- good caching speed, therefore ideal for heavy traffic CMS'es
- It 'hooks' into the core classes therefore it doesn't 'meddle' with anything CI specific. You can upgrade to newer versions without problems.
- Since it 'hooks' into the core classes, no special namespaces or conventions exist.
- You can rewrite or use any url you want. Customers can build their own url's as long as they are valid url's (this you should of course check in a backend).
- Since we have a table that has a one to many relationship to 'models', you can add 'plugins' later.[/quote]

You mind sharing that code with us please.
#32

[eluser]n0xie[/eluser]
[quote author="easylancer" date="1243372018"]
You mind sharing that code with us please.[/quote]
We are a little busy atm but we do have plans to open-source our CMS as soon as we have resources available. We use it quite extensively in our company to rapidly build basic skeleton CMS'es. Since there are a lot of other good CI based CMS'es (Pyro and Blaze come to mind although it's been a while since I took a look at them) we haven't bothered yet. If you are really interested I could post a rough working copy for you to checkout.
#33

[eluser]easylancer[/eluser]
That would be nice if you could post it so I can see how the inner working is.




Theme © iAndrew 2016 - Forum software by © MyBB