I restructured my already working code. My earlier directory structure was as follows:
- web
- css
- style.css
- model
- db_functions.inc
- view
- view_functions.inc
- controller
- index.php
- css
Here is the code snippet which was working:
<?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();
?>
I now restructured the code to be:
- web
- model
- db_functions.inc
- view
- view_functions.inc
- controller
- model
- public
- css
- style.css
- js
- images
- index.php
- css
Now I modified my index.php code to be as follows (i commented out the db functions to narrow down the problem):
<?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();
?>
I get the error:
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
Not sure why I am getting this error. Is my include path wrong? I tried different combinations but did not help.
Thanks in advance.
PHP complains that the path
/citee/web/view/view_functions.incdoesn’t exist, and I also doubt it. Can youcd /citee/web/view/? I bet not.If you are trying to access it, you can do it (and is a better practice, thinking about future deployments to different structured server file-systems in the future) with a relative file path.
So, instead of
/citee/web/view/view_functions.inc, you can work from the path of index.php toward the correct relative path:../web/view/view_functions.inc(..stands for “go up a directory in the tree”, meaning it will go into your “citee” folder, and then access the “web” folder, and so on.)