在php中设置函数路径?
我在文件夹(dirC)中有gcm…这里是路径在php中设置函数路径?,php,path,include,include-path,Php,Path,Include,Include Path,我在文件夹(dirC)中有gcm…这里是路径 index.php dirA/ dirB/ dirC/GCM.php ----/config.php ----/sendMsg.php dirD/ dirE/dirE1/test.php //send from here dirF/ php的代码如下 class GCM { function __construct() { } /** * Sending Push
index.php
dirA/
dirB/
dirC/GCM.php
----/config.php
----/sendMsg.php
dirD/
dirE/dirE1/test.php //send from here
dirF/
php的代码如下
class GCM {
function __construct() {
}
/**
* Sending Push Notification
*/
public function send_notification($registatoin_ids, $message) {
// include config
include_once './config.php';
//other code here
echo 'test';
}
}
我成功地从sendMsg.php发送了消息,下面是代码
include_once './GCM.php';
$message="hello word";
$gcm = new GCM();
$registatoin_ids = array("SEJFOJOEUJFPUWPJR0923740JEU092308UPUPUAUOJLJLJJVPW634");
$message = array($message);
$result = $gcm->send_notification($registatoin_ids, $message);
echo $result;
我的问题是如何从test.php
设置路径以使用include_一次性与GCM.php通信
这里是test.php代码
include_once './GCM.php'; //my proble is here ???????????
$message="hello word";
$gcm = new GCM();
$registatoin_ids = array("SEJFOJOEUJFPUWPJR0923740JEU092308UPUPUAUOJLJLJJVPW634");
$message = array($message);
$result = $gcm->send_notification($registatoin_ids, $message);
echo $result;
提前谢谢。这个问题不是很清楚。但我认为问题是你制作了一个文件夹,你从中包括了,你不知道那是什么文件夹 因此,在php中有神奇的常量:
当您想要访问所需目录时,需要使用../,这意味着“向上移动一个目录” 例如: 我们有一个目录结构:
/website
/website/include
/website/template
假设我们在/website/template目录中。
如果我们想包括/website/include/GCM.php
我们可以用一个绝对路径来实现,/表示根目录:
include_once '/website/include/GCM.php';
我们可以通过相对路径来实现:
include_once '../include/GCM.php';
../表示“向上移动1个目录”
有关更多信息:从php文档中,您可以执行以下操作:
$path = '/dirC';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
在index.php(如果是控制器)中,或者在conf/prepend文件中,该文件包含在所有脚本中
然后是一个简单的
include('GCM.php')代码>将起作用。如果GCM.php在另一个目录中,您可以使用../(1目录向上)浏览该目录。使用2点(../)和(../)有什么区别?../是向上移动一个目录。/是当前目录吗