包括在PHP中 [英] includes in php

查看:186
本文介绍了包括在PHP中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中包含了很多页面,我遇到包含内部路径不正确的问题,有没有办法从root包含文件,
我试着这样做

I include many pages inside each other in my project, I face problem of incorrect paths inside the include, is there any way to include the file from the root, I try to make like this

require_once("$_SERVER['DOCUMENT_ROOT']/crm/includes/opendb.php");
require_once("./includes/opendb.php");
require_once("../includes/opendb.php");
require_once("includes/opendb.php");

并且所有包含文件时出错,任何建议都是PLZ?

and all makes error in includeing the file, any suggestion plz?

编辑

我有2个文件夹,控制器和包含,在控制器内我从include文件夹中调用opendb.php ,我在下面的答案中证明了这一点

I have 2 folders, controllers and includes, inside the controller I call opendb.php from includes folder, I make as demonstrated in an answer below

set_include_path('../includes/');
include 'opendb.php';

set_include_path('includes/');
include 'opendb.php';

但同样的错误

Warning: include(opendb.php) [function.include]: failed to open stream: No such file or directory in C:\AppServ\www\crm\controllers\Customer.controller.php on line 


推荐答案

$ _SERVER ['DOCUMENT_ROOT'] / crm / includes / opendb.php不正确:你不能在双引号内的数组键周围使用撇号。请尝试以下方法之一:

"$_SERVER['DOCUMENT_ROOT']/crm/includes/opendb.php" is incorrect: you can't use apostrophes around array keys inside double quotes. Try one of these:

require_once( $_SERVER['DOCUMENT_ROOT']."/crm/includes/opendb.php" );
require_once( "$_SERVER[DOCUMENT_ROOT]/crm/includes/opendb.php" );
require_once( "{$_SERVER['DOCUMENT_ROOT']}/crm/includes/opendb.php" );

这篇关于包括在PHP中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆