我有一个日历类,它输出一个 HTML 表格,表格单元格代表一个月中的某一天,但是我应该将 HTML 嵌入到类文件中吗?我担心的是,如果我必须修改 HTML(即向元素添加 ID),那么我将不得不调整类文件。
我目前没有在我的项目中使用 MVC 模式,所以没有 View 是一种选择。
我的缩减类文件如下(对于这个例子,我假设 1 个月是 4 周):
class calendar {
function __construct(){
}
function output() {
print "<table>";
for ($week=0; $week < 4; $week++) {
print "<tr>";
for ($day=0; $day < 7; $day++) {
print "<td></td>";
}
print "</tr>";
}
print "</table>";
}
有没有其他我没有想到的方法可以将 HTML 与类文件分开 提前致谢
最佳答案
最简单的模板
// myTemplate.phtml
<div><?php echo $xy; ?></div>
// SomewhereElse.php
class MyClass {
public function myMethod () {
$xy = 'something';
include('myTemplate.phtml');
}
}
关于php - 在 php 类文件中嵌入 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6123893/