Home > Backend Development > PHP Tutorial > php-include_once - include_once包含php文件出错

php-include_once - include_once包含php文件出错

WBOY
Release: 2016-06-06 20:34:23
Original
1201 people have browsed it

写了一个小练习,目录结构如下
php-include_once - include_once包含php文件出错
/view/user/userRegister.php发送
post请求给/service/user/userRegister.php
userRegister.php文件include_once了
/model/user/userModel.php
userModel.php文件include_once了
/model/db.php
具体的包含的代码是
userRegister.php中include_once '../../model/user/userModel.php'
--》userModel.php'中include_once '../db.php'
在eclipse中按住ctrl是可以切换的但是还是报了这样的一个错
php-include_once - include_once包含php文件出错

回复内容:

写了一个小练习,目录结构如下
php-include_once - include_once包含php文件出错
/view/user/userRegister.php发送
post请求给/service/user/userRegister.php
userRegister.php文件include_once了
/model/user/userModel.php
userModel.php文件include_once了
/model/db.php
具体的包含的代码是
userRegister.php中include_once '../../model/user/userModel.php'
--》userModel.php'中include_once '../db.php'
在eclipse中按住ctrl是可以切换的但是还是报了这样的一个错
php-include_once - include_once包含php文件出错

看得很乱,实际上,你可以在入口文件即 index.php中,定义一个代表根目录(比如D:\www\Xproject)的变量app_dir,每次include文件的时候,拼接上这个app_dir就可以了。免得这么乱。

app_dir的获取可以用魔术变量DIR来获取,当然是否要截取处理等等自己搞掂,能把项目根目录拿到就行。

说了这么多,没说出重点,请用:绝对路径。谢谢 @libraco 。

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template