我在项目中使用了未定义的常量错误。这是设置
常数是;
define('VIEW_ROOT_ADMIN', '/views/admin');
并且调用的文件是
<?php
$mode = file_get_contents('../app/mode.php');
require '../app/' . $mode . '.php';
require VIEW_ROOT_ADMIN . '/index.php';
这是发生错误的地方;
Notice: Use of undefined constant VIEW_ROOT_ADMIN - assumed 'VIEW_ROOT_ADMIN'
这个奇怪的部分是它在
下面的文件结构上工作正常define('VIEW_ROOT', '/views');
<?php
$mode = file_get_contents('app/mode.php');
require 'app/' . $mode . '.php';
require VIEW_ROOT . '/index.php';
这里的任何帮助都会很好: - )
这是文件结构
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
答案 0 :(得分:0)
你应该
<?php
require_once('/app/mode.php'); // this sets $mode = 'development' or similar
require_once('/app/' . $mode . '.php'); // this sets the constants
之后,定义了常量,您可以使用它:
require_once(VIEW_ROOT_ADMIN . '/index.php');
我使用require_once()来支持require()以防止文件被多次包含。