要求功能无法正常工作

时间:2017-02-18 05:37:18

标签: php namespaces

我在单个php文件中使用了三个php文件,因为有三个独立的函数,所以我使用php' s require()函数包含了这些文件。首先,看看我的文件的结构

  • 阿比

  • 验证

    • Controller.php这样

    • Loging.php

    • Signup.php

  • 安全

    • Controller.php这样

在身份验证目录的controller.php中,我在安全目录中需要controller.php文件,所以我只是编写了这样的代码,

namespace AppAuthentication;

Require '../security/controller.php';

现在执行Authentication目录的controller.php文件时,它已生成此致命错误require() : Failed to opening required...... No such file or directory. ...

我该怎么办?

1 个答案:

答案 0 :(得分:0)

当require,require_once,include,include_once和访问文件系统的各种其他函数时,它相对于最初调用的文件进行访问。现在有一个简单的方法来解决这个问题,以便它相对于您正在进行包含的实际文件,即使用__DIR__的魔术常量。它放在的实际文件中。

namespace AppAuthentication;

Require __DIR__ . '/../security/controller.php';
相关问题