2017-01-30 4 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は、データベース接続が含まれています。 admin_header.phpへ

は、私はこれらの2つのファイルを追加しました:

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

だから私はそう後で私は他の場所でのヘッダファイルを必要とする必要がadmin_header.phpにこれら2つのファイルを追加します。

私は管理者/ 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 '../app/config.php'; ' – JustOnUnderMillions

+0

のように' config.php'を最初にインクルードする必要があります@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

関連する問題