重构代码结构给了我php中的包含问题

edo*_*ahg 3 php path include

我重新构建了我已经运行的代码.我之前的目录结构如下:

  • 卷筒纸
    • CSS
      • style.css文件
    • 模型
      • db_functions.inc
    • 视图
      • view_functions.inc
    • 调节器
    • 的index.php

以下是正在运行的代码段:

<?php
    $pageTitle = "Citee.me";

    //include view functions
    include ('view/view_functions.inc');
    //incldue db functions
    include ('model/db_functions.inc');
    doHtmlHeader($pageTitle);
    doBody();
    testMySQL();
    doHtmlFooter();
?>
Run Code Online (Sandbox Code Playgroud)

我现在重构了以下代码:

  • 卷筒纸
    • 模型
      • db_functions.inc
    • 视图
      • view_functions.inc
    • 调节器
  • 上市
    • CSS
      • style.css文件
    • JS
    • 图片
    • 的index.php

现在我修改了我的index.php代码如下(我注释掉db函数来缩小问题范围):

 <?php
    $pageTitle = "Citee.me";

    //include view functions
    include ('/citee/web/view/view_functions.inc');
    //incldue db functions
    //include ('./model/db_functions.inc');
    doHtmlHeader($pageTitle);
    //doBody();
    //testMySQL();
    doHtmlFooter();
?>
Run Code Online (Sandbox Code Playgroud)

我收到错误:

PHP Warning:  include(/citee/web/view/view_functions.inc): failed to open stream: No such file or directory in /Library/WebServer/Documents/citee/public/index.php on line 6

PHP Warning:  include(): Failed opening '/citee/web/view/view_functions.inc' for inclusion (include_path='.:/usr/lib/php') in /Library/WebServer/Documents/citee/public/index.php on line 6

PHP Fatal error:  Call to undefined function doHtmlHeader() in /Library/WebServer/Documents/citee/public/index.php on line 9
Run Code Online (Sandbox Code Playgroud)

不知道为什么我收到此错误.我的包含路径错了吗?我尝试了不同的组合,但没有帮助.

提前致谢.

ani*_*son 7

PHP是您的朋友,它为您提供了执行代码的完整路径:

/Library/WebServer/Documents/citee/

/citee/

仅仅因为您无法访问Web根目录之外的文件并不意味着PHP不会在您的Web根目录之外.