行き詰まったのでヒントが欲しいです。Cypher Query を起動すると
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\ への呼び出し」...
最後に、ノードからラベル (1 つまたは複数) を取得し、それらを 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
さらに出力が必要な場合は、投稿することもできます。
ご支援いただきありがとうございます - 非常に感謝