【发布时间】:2012-04-26 23:23:46
【问题描述】:
我有一个脚本来自其他来源,而不是我自己的想法。我需要让它工作的原因是在 opencart 安装的顶部安装一个 drupal 顶部菜单,以便能够使用高级 cms 功能,同时让 opencart 处理高级网上商店功能。
问题是从脚本打印到缓存文件的菜单使用相对 url.s。这当然意味着当需要菜单进入子域上的opencart时,路径显示子域的路径。不好。
编辑:好的,我得到了代码,有一段时间有点困惑,到处都是 $content 和 $contents。将下面的代码更改为现在的样子。我需要将时间间隔更改为 1 秒,否则 drupal 页面的行为非常奇怪。
<?php
$cache_time = 1; // Time in seconds to keep a page cached
$cache_folder = 'cache'; // Folder to store cached files (no trailing slash)
$cache_filename = $cache_folder.md5($_SERVER['REQUEST_URI']);
// Location to lookup or store cached file
//Check to see if this file has already been cached
// If it has get and store the file creation time
$cache_created = (file_exists($cache_file_name)) ? filemtime($cache_filename) : 0;
if ((time() - $cache_created) < $cache_time) {
readfile($cache_filename);
// The cached copy is still valid, read it into the output buffer
die();
}
?>
<?php ob_start(); // Turns on output buffering ?>
<?php $contents = ob_get_contents(); ?>
<!-- //Stores the contents of the buffer in a variable as a string -->
<?php if ($page['header_menu']): ?>
<div id="header-menu-wrapper">
<div id="header-menu">
<?php print render($page['header_menu']); ?>
</div>
</div>
<?php endif; ?>
<?php
$contents = ob_get_contents();
$contents = str_replace('href="','href="http://yourdomain.com', $contents);
file_put_contents($cache_filename, $contents());
ob_end_flush();
?>
另外,如果能够将缓存文件始终写入相同的文件名,那就太好了,否则它不会有多大好处,因为商店中的菜单不会随着 drupal 菜单的变化而改变,因为更改将导致新的文件名。
我在这里查看了有关 drupal 和绝对路径的其他问题,但要么我不够了解,要么它们不适用。
【问题讨论】:
标签: drupal url menu opencart absolute