I have two PHP files:
- template.php
- template.html.php
The first is the class definition for Template. The second contains an actual HTML-based template, however with PHP constructs (hence the .PHP extension). I’d call this a hybrid html/php file.
Is it possible to create some function in the Template-class (special_include_parse()) which takes a:
- $path (to a hybrid html/php file)
- $model (which is passed to the code in the hybrid html/php file so that it can be referenced using $this->getModel() or $model or whatever…)
?
template.php
class Template {
function Parse($model) {
//include('/var/www/template.html.php');
//fopen('/var/www/template.html.php');
$return = special_include_parse('/var/www/template.html.php', $model);
}
}
template.html.php
<html>
<head>
<title><? echo $this->getModel()->getTitle(); ?></title>
</head>
</html>
Um… why not just set $this (although I wouldn’t call it that) and include/require the template.html.php considering it’s basically PHP syntax? Basically:
Personally though I think this is a prime example of making something more difficult than it is by introducing an unnecessary (in fact, counterproductive) object abstraction to something that’s otherwise pretty straightforward:
and
I’m not sure why you’re overcomplicating it or rather what you’re trying to achieve.