I’m using a new no-name framework that I’m not completely familiar with and I’m hung up on how I will add dynamic content from the database in this environment.
In the index controller, I’m forced to have an index function that answers all requests for index.html. If I wanted to create a second page dynamically from a data source, how do I go about this without having to add a controller for this new page? All requests are currently being routed by htaccess. Without getting into code snippets, I’m simply looking for the logic on how this is generally handled.
Okay, the question is a bit vague, so the answer might seem a little vague too.
Let’s have an example to help visualise. You have a newspaper website, so you serve lots of articles – but all from one dynamic page…
And so on.
You then add some .htaccess (mod_rewrite) love to the site…
And you rewrite those URIs back to the articles.do page.
So in your articles.do page, you use the request string (Article=Value) to query the Article table and get back the relevant page…
And then you pop that onto the page.
Shout if I’ve missed the point on this question.
mod_rewrite example
This is the mod_rewrite rule for the example above, it maps the restful URI back to the articles.do URI.
The easiest way to explain this (not the technical way to explain this) is:
1) The first bit (^Articles/) looks for any address that starts with “Articles/”
2) The second bit (([^/.]+)/) represents “Whatever comes between the “/” after Articles and the next “/” after that, which in this example is the title of the article.
You can capture more parameters by adding more “([^/.]+)/” segments to the end…
In this example you could convert
into