包含文件时的路径错误

时间:2017-01-30 15:10:53

标签: php

我需要一些文件并且无法正确显示路径。

这是我当前的文件夹和文件结构: enter image description here

所以我在config.php中定义了一些常量,如下所示:

<div class="col-md-3">
    <span class="fa-stack fa-4x">
        <i class="fa fa-circle fa-stack-2x text-primary">ico#1</i>
        <i class="fa fa-user fa-stack-1x fa-inverse">ico#2</i>
    </span>
    <h4 class="text-center">Title</h4>
    <p class="text-muted">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>

.col-md-3 {
  text-align: center;
}

start.php只包含数据库连接。

对于admin_header.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');

所以我想将这两个文件添加到admin_header.php中,所以稍后我只需要在其他地方使用头文件。

当我需要admin / index.php

中的以下文件时
require APP_ROOT . '/config.php';
require APP_ROOT . '/start.php';

我收到以下错误:

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

1 个答案:

答案 0 :(得分:0)

我认为你的文件没有真正加载,因为你有:

require APP_ROOT . '/config.php';

和config.php 包含define('APP_ROOT', __DIR__);

将其更改为,它应该有效:

require  __DIR__ . '/config.php';