【发布时间】:2011-12-05 14:03:40
【问题描述】:
好吧,我的问题很简单,但有点难以接受解决方案,但无论如何.. 如下,我有一个'mini-framework',可以编写一个单一的方案,帮助我很多,加速一些事情的工作,然而,问题是即使是视图,在某种程度上,使用模板方案非常容易而且非常有趣,因为当你必须改变任何东西related to visualization时,模板只会改变,但是,及时到render this template,这是最好的方法吗?我目前正在这样工作:
<?php
class View {
private $vars;
public function __get ( $var ) {
if ( isset( $this->vars [ $var ] ) ) {
return $this->vars[ $var ];
}
}
public function assign ( $var , $value ) {
$this->vars [ $var ] = $value;
}
public function show ( $template ) {
include_once sprintf ( "%s\Templates\%s" , __DIR__ , $template ) ;
}
}
这不是完整的代码,我正在构建结构和审查方案,所以我做了以下..
<?php
require_once 'MVC/Views/View.php';
$View = new View ( ) ;
$View->assign( 'title' , 'MVC, View Layer' ) ;
$View->show ( 'test.phtml' );
还有模板
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title><?php echo $this->title ?></title>
</head>
<body>
</body>
</html>
输出是正确的,all working as expected,但我的问题是:这是最好的方法吗?包含文件并让play解释.phtml中写的代码
【问题讨论】:
标签: php templates output-buffering