Мне нужен намек, поскольку я застрял. Когда я огонь мой Cypher запросКак получить доступ к коллекции меток из Cypher Query в PHP?
MATCH (startNode) -[r]- (zielNode)
return labels(startNode) as startLabel
я получаю в браузере столбец в виде массива, в котором перечислены все метки узла «startNode» имеет.
Выбрасывание результата с помощью print_r Я получаю объектный код, хотя я предполагал, что могу также захватить это как массив в PHP. Я попытался
Использование цикла Еогеасп с классической
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 \ "...
В конце концов, я хочу, чтобы у меня была лабиринт ls (один или несколько) из узла и работать с ними в PHP как массив. Я думаю, что это всего лишь небольшая проблема, но я не могу найти решение. Если кто-то есть намек, я был бы счастлив - спасибо
Update
Вот запрос я использую:
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']? –
Обновлен вопрос. – Balael