douqiao5552 2016-03-14 18:07
浏览 1105
已采纳

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 18: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.

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

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题