目前正在尝试使用带有php项目的ESI包含清漆缓存系统的功能。在我的场景中,我需要访问esi标签内的php变量。类似于...... ...
<p class="dt5">This article was read <esi:include src="http://localhost/live24/esi/viewCount" /> times. </p>
这里是esi标签内的完整网址,它工作正常,即从服务器获取读取计数,页面的其余部分从缓存提供。但是如何生成一个动态URL,我可以将其传递给esi标签。
我尝试了类似的事情......
<?php $url = site_url() . "/esi/viewCount" ?>
或
<?php $url = "http://localhost/live24/esi/viewCount" ?>
<p class="dt5">This article was read <esi:include src="$(url)" /> times. </p>
因为$(variable_name)
或$(variable_name{key_name})
是在esi标记内添加变量的语法,但看起来它在访问PHP变量时不起作用。
我也试过这样的事情......
<p class="dt5">This article was read<esi:include src="http://$(SERVER{NAME})/live24/esi/viewCount" /> times. </p>
这是有效的。表示我可以从esi标签内部访问超全局。
有没有办法访问esi标签内的php变量或任何其他方式来生成在esi include中使用的动态URL。
答案 0 :(得分:0)
找到了一个解决方案,实际上非常简单明了。应该早点考虑一下。
首先是代码段..
<p class="dt5">This article was read
<esi:remove>
<?php $esiUrl = "http://localhost/bdlive24/esi/viewCount"; ?>
</esi:remove>
<!--esi
<esi:include src=<?php echo $esiUrl; ?> />
-->
times</p>
这里的技巧是引入<esi:remove>
标签。删除标记内的任何标记代码都将被忽略,并且将执行php代码。所以现在esi:remove标签内的任何动态url生成都可以在esi:include标签中绑定它。
<!-- ... -->
当启用ESI处理时,此标记将被静音删除,如果禁用ESI处理,此标记将生效并使esi:include标记处于非活动状态。
任何有任何其他想法的人,请分享....