php create front-controller to include file from other folder if not exist

老子叫甜甜 提交于 2019-12-11 05:14:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!