问题
I'm creating a php front-controller because I need to include file from other folders instead of creating the same file for those that have the same content
Example of a directory structure
rome
- index.php
- detail.php
- show.php
another folder
london
- index.php (same content as rome/index.php folder)
- detail.php (different content as rome/detail.php folder)
- show.php (same content as rome/show.php folder)
Then london folder must include only detail.php that have different content from rome/detail.php and "index" and "show" must be loaded from rome folder
And this is my htaccess / front-controller
.htaccess
RewriteEngine On
RewriteRule . /front-controller.php [L]
front-controller.php
path = "{$_SERVER['DOCUMENT_ROOT']}$_SERVER['REQUEST_URI']}";
if (! file_exists ($path) ) include str_replace("london" , "rome" , $path );
The now I have problem for that file that include other content...
For example, my rome/index.php have
include 'content/header.php'
And when I load london/index.php I have the error
'content/header.php' failed to open stream: No such file or directory
EDIT
these are the error
Warning: require(content/php/config.php): failed to open stream: No such file or directory in /home/debian/www/rome/content/php/start.php on line 17
Fatal error: require(): Failed opening required 'content/php/config.php' (include_path='.:/usr/share/php:/usr/share/pear:') in /home/debian/www/rome/content/php/start.php on line 17
来源:https://stackoverflow.com/questions/41848860/php-create-front-controller-to-include-file-from-other-folder-if-not-exist