我正在尝试阅读本教程:http ://www.sitepoint.com/adding-social-network-features-php-app-neo4j/但使用 Symfony 框架而不是 Silex。
我已经能够将 Neo4j 设置为与 Symfony 一起运行,并且能够将用户数据正确地添加到图表中。现在我想在列表中显示所有用户的电子邮件地址。我采用了这个脚本:
public function home(Application $application, Request $request)
{
$neo = $application['neo'];
$q = 'MATCH (user:User) RETURN user';
$result = $neo->sendCypherQuery($q)->getResult();
$users = $result->get('user');
return $application['twig']->render('index.html.twig', array(
'users' => $users
));
}
并将其改编为:
public function showUsersAction()
{
$em = $this->container->get('neo4j.manager');
$query = 'MATCH (n:`User`) RETURN n';
$users = $em->cypherQuery($query);
//print_r($users);
return $this->render('UserBundle:Account:showUsers.html.twig', array('users' =>$users));
}
树枝看起来如下:
{% extends '::base.html.twig' %}
{% block content %}
<h1>get all users:</h1>
<ul>
{% for user in users %}
<li>{{ user.property('email') }}</li>
{% endfor %}
</ul>
{% endblock %}
但是树枝中的某些东西是错误的,我得到了错误:
Method "property" for object "Everyman\Neo4j\Query\Row" does not exist in UserBundle:Account:showUsers.html.twig at line 6