2015-01-06 24 views
0

例如,我們有一個php文件的目錄。如何做PHP prepend或包含文件到dir中的所有文件?

而且此文件夾中,我們有一個文件class.logger.inc

dir命令執行文件之前,我們需要「前面加上」或自動包含這個文件,從class.logger從其他PHP文件目錄中調用函數。

如何實現它不觸及文件。

看着auto_prepend_file但似乎它包括:如果腳本結束exit()

+0

除了'auto_pre pend_file'核心ini配置,您可能想要開發一個應用程序,其結構允許您使用post-pre-run方法。像EventManager一樣,帶有AwareInterface的ServiceManager,......很多可能性,在一個答案中解釋太長。 – DanFromGermany

+0

我想你應該看看[PHP自動加載](http://php.net/manual/en/language.oop5.autoload.php) – Scriptable

+0

@DanFromGermany我知道這個))。我有一個工作項目,不必觸摸文件。在php文件運行之前只有'prepend'。 – Daniel

回答

1

我會建議使用URL重寫,

.htaccess文件中:

RewriteRule ^originaldirectory/(.*)$ /wrapper.php?f=$1 [R=301,NC,L] 

及的內容封裝文件應該是

<?php 
include 'prepended_content.php'; 
include 'originaldirectory/'.$_GET['f']; 
include 'appended_content.php'; 
?> 
相關問題