【发布时间】:2015-05-07 18:12:17
【问题描述】:
我需要一个提示,因为我被卡住了。当我启动 Cypher 查询时
MATCH (startNode) -[r]- (zielNode)
return labels(startNode) as startLabel
我在浏览器中收到列作为数组,列出节点“startNode”的所有标签。
用 print_r 抛出结果我得到了目标代码,虽然我假设我也可以在 PHP 中将它作为数组抓取。我试过了
-
使用经典的 foreach 循环
foreach ($result as $row) { ... }希望我能抓住它,例如通过 $row['startLabel']。这失败了,因为我似乎得到了一个对象,而不是一个数组。然后我尝试将其转换为数组或在其上使用 get_obj_vars,但也失败了。
-
我查看了github中的文档发现
$node = $client->getNode('startNode); $nodeLabels = $client->getLabels($node);
试过了,要么得到整个对象,要么当我尝试类似的东西时
$label = $row[x]->getLabels($node);
一个错误“致命错误:调用未定义的方法 Everyman\Neo4j\Query\”...
最后,我想从一个节点获得标签(一个或多个),并在 PHP 中将它们作为数组使用。我认为这只是一个小问题,但我无法找到解决方案。如果有人有提示,我会很高兴 - 谢谢
更新
这是我使用的查询:
MATCH (startNode {uuid:"554b4e5e8fb38"}) -[r]- (targetNode) return labels(targetNode) as targetLabel
在 Neo4J 浏览器中,我得到了一个集合(正确):
targetLabel
[Group, SUB1]
[Group, SUB2]
[Group, SUB2]
[Group, Local]
这是 PHP 代码:
$queryString = '
MATCH (startNode {uuid:"554b4e5e8fb38"}) -[r]- (targetNode) return labels(targetNode) as targetLabel
';
$query = new Everyman\Neo4j\Cypher\Query($client, $queryString);
$result = $query->getResultSet();
foreach ($result as $row) {
echo gettype($row['targetLabel']);
var_dump($row['targetLabel']);
}
"gettype" says that "$row['targetLabel']" is an object. A var_dump gives
this result (I cutted it down as its a long output):
object(Everyman\Neo4j\Query\Row)#16 (5) { ["client":protected]=> object(Everyman\Neo4j\Client)#2 (8) { ["transport":protected]=> object(Everyman\Neo4j\Transport\Curl)#3 (7) { ["handle":protected]=> resource(27) of type (curl) ["scheme":protected]=> string(4) "http" ["host":protected]=> string(9) "localhost" ["port":protected]=> int(7474) ["path":protected]=> string(8) "/db/data" ["username":protected]=> string(5) "xx" ["password":protected]=> string(6) "xx" } ["entityMapper":protected]=> object(Everyman\Neo4j\EntityMapper)#11 (1) { ["client":protected]=> *RECURSION* } ["entityCache":protected]=> object(Everyman\Neo4j\Cache\EntityCache)#12 (3) { ["client":protected]=> *RECURSION* ["cache":protected]=> object(Everyman\Neo4j\Cache\Null)#13 (0) { } ["cacheTimeout":protected]=> int(0) } ["labelCache":protected]=> object(Everyman\Neo4j\Cache\Variable)#6 (1) { ["items":protected]=> array(0) { } } ["serverInfo":protected]=> array(14) { ["extensions"]=> array(0) { } ["node"]=> string(34) "http://localhost:7474/db/data/node" ["node_index"]=> string(40) "http://localhost:7474/db/data/index/node" ["relationship_index"]=> string(48) "http://localhost:7474/db/data/index/relationship" ["extensions_info"]=> string(33) "http://localhost:7474/db/data/ext" ["relationship_types"]=> string(48) "http://localhost:7474/db/data/relationship/types" ["batch"]=> string(35) "http://localhost:7474/db/data/batch" ["cypher"]=> string(36) "http://localhost:7474/db/data/cypher" ["indexes"]=> string(42) "http://localhost:7474/db/data/schema/index" ["constraints"]=> string(47) "http://localhost:7474/db/data/schema/constraint" ["transaction"]=> string(41) "http://localhost:7474/db/data/transaction" ["node_labels"]=> string(36) "http://localhost:7474/db/data/labels" ["neo4j_version"]=> string(5) "2.2.1" ["version"]=> array(4) { ["full"]=> string(5) "2.2.1" ["major"]=> string(1) "2" ["minor"]=> string(1) "2" ["release"]=> string(1) "1" } } ["openBatch":protected]=> NULL ["nodeFactory":protected]=> object
如果您需要更多输出,我也可以发布。
感谢您的支持 - 非常感谢
【问题讨论】:
-
您应该可以访问
$row['startLabel']。 $row 对象实现了 ArrayAccess 接口。 $row['startLabel'] 的值是多少? -
更新了问题。