Require(): 需要打开失败 (include_path='.;C:\xampp\php\PEAR')
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35994857/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Require(): Failed opening required (include_path='.;C:\xampp\php\PEAR')
提问by aasd
I have created a website using mvc framework, but I cant include php files in files that are from another folder. For example, I have model, view, controller and core folders, if I do the following require 'Core/User.php'
; in a view file in view folder, then I get the following error:
我已经使用 mvc 框架创建了一个网站,但我无法在来自另一个文件夹的文件中包含 php 文件。例如,如果我执行以下操作,我有模型、视图、控制器和核心文件夹require 'Core/User.php'
;在视图文件夹中的视图文件中,然后我收到以下错误:
Warning: require(Core/User.php): failed to open stream: No such file or directory
in C:\xampp\htdocs\k2\View\customer-management.php on line 2
Fatal error: require(): Failed opening required 'Core/User.php'
(include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\k2\View\customer-management.php
on line 2
I've tried using ../Core/User.php
, but the application becomes too messy and i need a cleaner way of doing this, perhaps working with php.ini or .htaccess to allow me to just include('Core/User.php');
from another folder. Any help would be appreciated.
我试过使用../Core/User.php
,但应用程序变得太混乱了,我需要一种更简洁的方法来做到这一点,也许使用 php.ini 或 .htaccess 来允许我include('Core/User.php');
从另一个文件夹中访问。任何帮助,将不胜感激。
回答by Dan
There are two ways that I would do this. Both are ways of adding 'C:\xampp\htdocs\k2' to your include path
我有两种方法可以做到这一点。两者都是将 'C:\xampp\htdocs\k2' 添加到包含路径的方法
- Use
.htaccess
- 用
.htaccess
Add this line to you .htaccess
file in the web root. You can add other directories as desired
将此行添加到.htaccess
Web 根目录中的文件中。您可以根据需要添加其他目录
php_value include_path '.;C:\xampp\php\PEAR;C:\xampp\htdocs\k2'
Makse sure Apache is configured to allow htacess to work: Number 4
确保 Apache 已配置为允许 htacess 工作:编号 4
- If you have some "config" file that is always included, you can add this line to it to set the include path
- 如果您有一些始终包含的“配置”文件,您可以在其中添加这一行以设置包含路径
set_include_path(get_include_path() . PATH_SEPARATOR . 'C:\xampp\htdocs\k2');
set_include_path(get_include_path() . PATH_SEPARATOR . 'C:\xampp\htdocs\k2');
This makes your code more portable than using relative or absolute path, since there is only one place to make changes when file structures change.
这使您的代码比使用相对或绝对路径更具可移植性,因为在文件结构更改时只有一个地方可以进行更改。