用PHP即时渲染它看起来有点像这样的HTML表:缓存包含或必需的文件,以便它可以反复使用?
--------------------------------------------------
| title | description | actions |
-------------------------------------------------|
| title1 | desc1 | edit/delete |
| title2 | desc2 | edit/delete |
| title3 | desc3 | edit/delete |
| title4 | desc4 | edit/delete |
--------------------------------------------------
的代码是这样的(!精简版没有thead
,tbody
等在此examle):
<table>
<?php foreach ($tableData as $row): ?>
<tr>
<!-- Render columns (title, description)
<?php foreach ($columnData as $column): ?>
<td>
<?= $row[$column['name']]; ?>
</td>
<?php endforeach; ?>
<!-- Render actions -->
<?php foreach ($actions as $action): ?>
<td>
<?= include($action); // include the proper action button! ?>
</td>
<? endforeach; ?>
</tr>
<?php endforeach; ?>
</table>
这给了我想要的结果。但我只有一个问题。当我有1000多条记录时,它会变得很慢。我已经注意到这是因为我为每个表格行都做了include
。当我删除include
时,一切运行速度非常快。
included
文件包含一些PHP逻辑。所以我不能只做一个file_get_contents
。那么,我可以,但是我必须使用eval()
来解析内容。但我宁愿不使用该功能。
所以,现在我想知道是否有可能以某种方式缓存包含的文件?所以PHP不会主动地一遍又一遍地包含实际的文件,而是从缓存中获取它?是这样的可能吗?
或者有没有更好的选择?
Thamks,没有想到这一点,但这可能是最好的方法。现在去看看它。 – Vivendi 2013-02-09 13:51:45