设置php中的函数路径


setting function path in php?

我有gcm在文件夹(dirC)…这里的路径

index.php
dirA/    
dirB/    
dirC/GCM.php    
----/config.php
----/sendMsg.php
dirD/
dirE/dirE1/test.php            //send from here
dirF/

gcm.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';
     }
}

和i成功地从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;

我的问题是如何设置路径使用include_once从test.php与GCM.php通信?

here test.php code

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;

thanks in advance.

当你想进入你想要的目录时,你需要使用../,表示"向上移动一个目录"。

的例子:我们有一个目录结构:

/website
/website/include
/website/template

假设我们在/website/template目录下。如果我们想包含/website/include/GCM.php

我们可以使用绝对路径,/表示根目录:

include_once '/website/include/GCM.php'; 

我们可以使用一个相对路径:

include_once '../include/GCM.php';

. ./表示"向上移动1个目录"。

更多信息:http://www.geeksengine.com/article/absolute-relative-path.html

这个问题不是很清楚。但我认为问题在于你创建了一个文件夹,你包含了其中的内容但你不知道那是哪个文件夹?

在php中有魔法常数:http://php.net/manual/en/language.constants.predefined.php

在php文档中可以这样做:

$path = '/dirC';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);

在你的index.php中(如果它是你的控制器),或者在conf/preend文件中,它包含在你所有的脚本中。

那么一个简单的include('GCM.php');将工作