在PHP PDO中对我的项目使用未定义的常量错误

I have an Use of undefined constant error on my project. Here is the setup

The constant is;

define('VIEW_ROOT_ADMIN', '/views/admin');

and the file called from is

<?php
$mode = file_get_contents('../app/mode.php');

require '../app/' . $mode . '.php';

require VIEW_ROOT_ADMIN . '/index.php';

This is where the error occurs;

Notice: Use of undefined constant VIEW_ROOT_ADMIN - assumed 'VIEW_ROOT_ADMIN'

The strange part of this is that it works fine on this file structure below

define('VIEW_ROOT', '/views');

<?php
$mode = file_get_contents('app/mode.php');

require 'app/' . $mode . '.php';

require VIEW_ROOT . '/index.php';

Any help here would be good :-)

This is the file structure

ROOT----
    |--admin
        |--index.php
    |--app
        |--development.php //Here are the contants define('VIEW_ROOT', '/views'); and define('VIEW_ROOT_ADMIN', '/views/admin');
        |--mode.php
        |--production.php
    |--views
        |--admin
            |--index.php
        |--index.php
    index.php

You should

<?php
require_once('/app/mode.php');   // this sets $mode = 'development' or similar
require_once('/app/' . $mode . '.php');   // this sets the constants

After that, the constant is defined and you can use it:

require_once(VIEW_ROOT_ADMIN . '/index.php');

I use require_once() in favor of require() to prevent files to be included more than once.