douqiao5552 2016-03-14 10:07
浏览 1120
已采纳

Require():需要打开失败(include_path ='。; C:\ xampp \ php \ PEAR')

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:

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.

  • 写回答

1条回答 默认 最新

  • drzdu44226 2016-03-14 10:19
    关注

    There are two ways that I would do this. Both are ways of adding 'C:\xampp\htdocs\k2' to your include path

    1. Use .htaccess

    Add this line to you .htaccess file in the web root. You can add other directories as desired

    php_value include_path '.;C:\xampp\php\PEAR;C:\xampp\htdocs\k2'
    

    Makse sure Apache is configured to allow htacess to work: Number 4

    1. 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');

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部