要求函数不能正常工作
问题描述:
我在单个php文件中使用三个php文件,因为有三个分离的函数,所以我通过使用php的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. ...
我该怎么办?
答
当require,require_once,include,include_once和其他访问文件系统的函数时,它是相对于最初调用的文件的访问。现在有解决这个简单的方法,以便它相对于你从做夹杂实际的文件,该文件是使用__DIR__
的幻常量,它被放置在实际文件的目录。
namespace AppAuthentication;
Require __DIR__ . '/../security/controller.php';