2017-01-30 1 views
1

일부 파일이 필요하고 경로를 올바르게 가져 오는 데 문제가 있습니다. enter image description here파일을 포함 할 때 경로가 잘못되었습니다.

그래서 나는이 같은 config.php를 일부 상수를 정의 :

여기에 내 현재 폴더 및 파일 구조입니다

define('APP_ROOT', __DIR__); 
define('VIEW_ROOT', APP_ROOT . '/views'); 
define('TEMPLATE_ROOT', APP_ROOT . '/views/templates'); 
define('BASE_URL', 'http://localhost:8080/site'); 

start.php는 데이터베이스 연결을 포함합니다. 그래서 나중에 난 단지 다른 장소에서 헤더 파일을 필요로 할

require APP_ROOT . '/config.php'; 
require APP_ROOT . '/start.php'; 

그래서 나는 admin_header.php에이 두 파일을 추가하려면 다음 admin_header.php으로

나는이 두 파일을 추가했습니다.

나는 관리자에서 아래의 파일을 필요할 때/index.php에

require TEMPLATE_ROOT . '/admin_header.php'; 
require VIEW_ROOT . '/admin/index.php'; 
require TEMPLATE_ROOT . '/admin_footer.php'; 

나는 다음과 같은 오류를 얻을 : 당신이 있기 때문에

Notice: Use of undefined constant TEMPLATE_ROOT - assumed 'TEMPLATE_ROOT' in F:\wamp64\www\site\admin\index.php on line 2 

Warning: require(TEMPLATE_ROOT/admin_header.php): failed to open stream: No such file or directory in F:\wamp64\www\site\admin\index.php on line 2 

Fatal error: require(): Failed opening required 'TEMPLATE_ROOT/admin_header.php' (include_path='.;C:\php\pear') in F:\wamp64\www\site\admin\index.php on line 2 
+0

당신이'index.php' 전에'config.php'를 호출하고 있습니까? (또는 index.php 포함) –

+0

** 치킨 & 에그 파라독스 ** :'APP_ROOT가 필요합니다. '/config.php';'하지만'config.php'에서는 처음으로'APP_ROOT' 상수를 정의합니다. 큰 논리 문제. 'admin/index.php'는'require '와 같이'config.php'를 먼저 포함해야합니다 .. ../app/config.php'; ' – JustOnUnderMillions

+0

@Antonis : VIEW_ROOT가 필요합니다. '/admin/index.php'; 메인 admin/index.php보기입니다 – PapT

답변

0

내가 파일의 어느 것도 정말로드되지 생각 :

require APP_ROOT . '/config.php'; 

및 config.php : define('APP_ROOT', __DIR__);

로 변경을하고, 그것을 작동합니다 :

require __DIR__ . '/config.php'; 
+0

고마워하지만 그것은 작동하지 않았다. – PapT

+0

'APP_ROOT'을 모두 __DIR__로 변경 했습니까? – mrbm

+0

config.php 또는 admin_header.php 또는 두 가지 모두를 의미합니까? – PapT

관련 문제