I am working on a small page in PHP that does not need the strength of a full structure. One thing that I really missed in my previous work in Ruby-on-Rails is the ability to efficiently transfer page content using "content_for".
I was wondering, how could you create a page life cycle that would perform the same effect in PHP?
So here is a simple example:
Say you have a template defining an index page, only a repeating title and menu that you want to use on all of your pages. So your file index.phplooks basically like this:
...header stuff...
<body>
<?php include $file.'.php'; ?>
</body>
...footer stuff...
EDIT: Thanks for the tips on securing URLs, but let me assume that I am receiving a user request safely :)
Now let's say in the header you want to put:
<head>
<title><?php echo $page_title; ?></title>
</head>
It would be nice to specify the header in the included file, so in the url http://example.com/index.php?p=testyou load test.php, and this file looks like this:
<?php $page_title = 'Test Page'; ?>
... rest of content ...
Now, obviously, this will not work, because the included page (index.php) is loaded before the variable is set.
In Rails, here you can pass up-page stuff with a function content_for.
My question is this: what will be the easiest, fastest way that you can all imagine to implement such "content_for" functionality in PHP?
, - , , .