我有一個腳本放在其他來源,而不是我自己的想法。我之所以需要這個工作,是爲了讓opencart能夠使用優秀的cms功能,同時讓opencart能夠處理卓越的網上商店功能,讓一個Drupal頂級菜單進入opencart安裝的頂層。需要幫助打印drupal菜單的緩存並將鏈接的相對路徑轉換爲絕對路徑
問題是,從腳本打印到緩存文件的菜單使用相對url.s.這當然意味着,當菜單需要放入子域的opencart中時,路徑將顯示子域的路徑。不好。
編輯:好的,我得到的代碼工作,有一段時間有點困惑,什麼與所有$內容和$內容無處不在。將代碼更改爲現在的樣子。我需要將時間間隔更改爲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和絕對路徑的其他問題,但是我不明白或者不適用。
甜!好吧,我得到的代碼工作,我得到的絕對路徑。非常感謝:)我沒有得到有關unique-key等等的東西,以及opencart在圖片中的位置。緩存文件保存在drupal安裝的根目錄下,我需要將它放入我在opencart中使用的主題中。所以我真的沒有試圖用opencart做更多的事情,除了導入實際的緩存文件。所以,我需要做的是確保它在drupal的根目錄中始終是相同的名稱,並覆蓋它自己。再次感謝Thanx :) – user1334233 2012-04-15 21:50:22
啊我明白了。沒問題。如果解決了這個問題,請點擊我答案旁邊的勾號:) – 2012-04-16 01:35:16
我試過點擊了,但是因爲我的名聲不靈敏,所以我無法投票。還是你的意思是點擊其他東西? – user1334233 2012-04-16 17:40:51