【发布时间】:2010-11-01 08:04:23
【问题描述】:
我有两个 PHP 文件:
- template.php
- template.html.php
第一个是 Template 的类定义。第二个包含一个实际的基于 HTML 的模板,但是带有 PHP 结构(因此是 .PHP 扩展名)。我称之为混合 html/php 文件。
是否可以在模板类 (special_include_parse()) 中创建一些函数,该函数需要:
- $path(到一个混合的 html/php 文件)
- $model(传递给混合 html/php 文件中的代码,以便可以使用 $this->getModel() 或 $model 或其他任何方式来引用它...)
?
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>
【问题讨论】:
-
听起来你实际上是在重新发明 Fry 模板系统:fry.sourceforge.net