[英]setting function path in php?
I have gcm in folder (dirC)...here the paths 我在文件夹(dirC)中有gcm ...这里的路径
index.php
dirA/
dirB/
dirC/GCM.php
----/config.php
----/sendMsg.php
dirD/
dirE/dirE1/test.php //send from here
dirF/
gcm.php have code bellow 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';
}
}
and i successfull send message from sendMsg.php,here the code 我成功地从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;
my question is how to set the path to communicate with GCM.php using include_once from test.php
? 我的问题是如何使用
test.php
include_once 设置与GCM.php通信的路径 ?
here test.php code 这是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;
thanks in advance.. 提前致谢..
The question is not really clear. 问题还不是很清楚。 But i think the problem is that you make a folder, from which you include and you dont know what folder that is?
但我认为问题是您创建了一个文件夹,其中包括文件夹,但您不知道该文件夹是什么?
For that you have magic constants in php: http://php.net/manual/en/language.constants.predefined.php 为此,您在php中具有魔术常数: http : //php.net/manual/zh/language.constants.predefined.php
When you want to get to your desired directory, you need to use ../, which means 'move one directory up'. 当您想进入所需目录时,需要使用../,这意味着“向上移动一个目录”。
Example: we have a directory structure: 示例:我们有一个目录结构:
/website
/website/include
/website/template
Imagine we are in /website/template directory. 假设我们位于/ website / template目录中。 If we want to include /website/include/GCM.php
如果我们要包含/website/include/GCM.php
We can do it with an absolute path, / means the root directory: 我们可以使用绝对路径来实现,/表示根目录:
include_once '/website/include/GCM.php';
We can do it with a relative path: 我们可以使用相对路径:
include_once '../include/GCM.php';
../ means 'move 1 directory up'. ../表示“向上移动1个目录”。
For more information: http://www.geeksengine.com/article/absolute-relative-path.html 有关更多信息: http : //www.geeksengine.com/article/absolute-relative-path.html
From php documentation you can do something like that : 从php文档中,您可以执行以下操作:
$path = '/dirC';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
In your index.php (if it's your controller), or in a conf/prepend file, which is included in all your script. 在您的index.php(如果它是您的控制器)中,或在conf / prepend文件中,该文件包含在所有脚本中。
Then a simple include('GCM.php');
然后是一个简单的
include('GCM.php');
will work. 将工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.