我最近一直在用这个Doctrine2 风格的 Neo4j 包装器进行测试。虽然以前从未使用过 Doctrine,但我已经从 Github 页面和 Doctrine 文档中删除了一些很好的示例,并且似乎无法通过某个点。我提取了 Neo4j-PHP-OGM 库,使用 Composer 下载了 Doctrine2,并将 EntityManager 程序化(用于测试)包含在bootstrap.php
.
/bootstrap.php
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/lib/HireVoice/Neo4j/Annotation/Entity.php';
require __DIR__ . '/lib/HireVoice/Neo4j/Annotation/Auto.php';
require __DIR__ . '/lib/HireVoice/Neo4j/Annotation/Property.php';
require __DIR__ . '/lib/HireVoice/Neo4j/Annotation/Index.php';
require __DIR__ . '/lib/HireVoice/Neo4j/Annotation/ManyToOne.php';
require __DIR__ . '/lib/HireVoice/Neo4j/Annotation/ManyToMany.php';
$em = new HireVoice\Neo4j\EntityManager(array(
'transport' => 'curl', // or 'stream'
'host' => 'localhost',
'port' => 7474,
// 'username' => null,
// 'password' => null,
// 'proxy_dir' => '/tmp',
// 'debug' => true, // Force proxy regeneration on each request
// 'annotation_reader' => ... // Should be a cached instance of the doctrine annotation reader in production
));
/用户.php
namespace Entity;
use HireVoice\Neo4j\Annotation as OGM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @OGM\Entity
*/
class User
{
/**
* @OGM\Auto
*/
protected $id;
/**
* @OGM\Property
* @OGM\Index
*/
protected $fullName;
function setFullName($fullname){
$this->fullname = $fullname;
}
}
/保存.php
require 'bootstrap.php';
require 'User.php';
$repo = $em->getRepository('Entity\\User');
$jane = new User;
$jane->setFullName('Jane Doe');
$em->persist($jane);
$em->flush();
在生产中,我将自动加载实体类,现在我只需要它们。在浏览器中加载save.php
时,它会引发此错误:
Fatal error: Class 'User' not found in C:\htdocs\neo4j-php\ogm\save.php on line 7
我不确定为什么,因为User.php
在bootstrap.php
. 关于为什么的任何建议?提前致谢。