我正在创建一个php前端控制器,因为我需要包含其他文件夹中的文件,而不是为那些具有相同内容的文件创建相同的文件
目录结构示例
[root]
- start.php
[rome]
- index.php
[subfolder]
- page.php
[london]
(no file)
此处文件的内容
的index.php
require '../start.php';
start.php
require 'subfolder/page.php';
rome / index.php正确显示page.php ......
现在在london文件夹中,这些是htaccess / front-controller
的.htaccess
RewriteEngine On
RewriteRule . front-controller.php [L]
前Controller.php这样
$path = $_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI'];
if (! file_exists ($path) ) include str_replace("london" , "rome" , $path );
当我调用london / index.php时,响应是
Warning: require(subfolder/page.php): failed to open stream: No such file or directory in ...
Fatal error: require(): Failed opening required 'subfolder/page.php'