Currently, I have a system that actively generates the pages on my site using PHP, more or less like so:
index.php ——include(query.php);—–> query.php grabs content from a file that corresponds to index.php
Query.php simply assembles the page from the mentioned index.php file and from header, footer, and navigation files.
The index.php file acts as a sort of proxy or label if you will so that when users visit the site, instead of having urls like “query.php?page=index” they have real pages.
The issue of course is that this is a bit convoluted. For each page of the site, I need 2 files: the “wrapper” file (such as index.php) and a content file to which it corresponds. I’d like to only be using a single file. The issue is that the single file should only contain the content of the page – not structure, header, footer etc.
So, what I’d like to be able to do is to be able to have index.php contain ONLYand a paragraph for example. When it is accessed, somehow PHP kicks in and applies a template and the header and footer.
Is PHP too high level a language to be able to do this? I know it is often done with Tomcat and java servlets, but I thought it would be cool to do with PHP.
EDIT: Important point, I don’t want to use GET variables.
It’s a bit hard to tell what you’re trying to do, but have you looked into using a framework such as Kohana or Synfony? This will do pretty much exactly what you’re asking.
If you’re looking for a good template system, I suggest PHPTAL.
Failing that, it doesn’t sound like you need to do anything that special. On the
index.phppage, why not just includeheader.php, the content, andfooter.php? Short of usingauto_append_fileandauto_prepend_file, you can’t add content to the page that is not explicitly in the code.It sounds like what you want to do is route all requests through a single point (like frameworks do). Let’s call it
main.php.On
main.phpyou would have:Then you would route all requests (using your server configuration) to “/main.php/pagename.” Then pagename would only need its respective content.