用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