4

我无法让 Doctrine 找到位于 www/entities/.. 中的实体类

我不断收到错误“致命错误:在第 7 行的 /home/dxs/public_html/create-event.php 中找不到类 'Event' ”.. 我觉得我几乎尝试了所有东西..

我调用的文件是:

创建事件.php:

<?php
require_once("bootstrap.php");
require_once("entities/Event.php");
$name = $argv[1];
$description = $argv[2];

$event1 = new Event;
$event1->setName("test");
$event1->setDescription("testdesc");

$entityManager->persist($event1);
$entityManager->flush();

echo "Created Event with ID " . $event1->getId() . "\n";

引导程序.php

<?php
use Doctrine\ORM\EntityRepository;

if(!class_exists("Doctrine\Common\Version", FALSE))

{

    require_once 'bootstrap_doctrine.php';

}

引导程序

<?php
use Doctrine\ORM\EntityRepository;

if(!class_exists("Doctrine\Common\Version", FALSE))
{

    require_once 'bootstrap_doctrine.php';

}

更新了引导学说

 <?php
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(dirname(__FILE__)));

use Doctrine\ORM\Tools\Setup;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;

require_once "Doctrine/ORM/Tools/Setup.php";

Setup::registerAutoloadPEAR();
$cl = new Doctrine\Common\ClassLoader('Entities', __DIR__);
$cl->register();

$isDevMode = true;

$path = array(__DIR__.'/entities');
$config = Setup::createAnnotationMetadataConfiguration($path, $isDevMode);

// database configuration parameters
$conn = array(
    'driver' => 'pdo_mysql',
    'user' => 'dxs',
    'password' => 'pass',
    'dbname' => 'db'

);
// obtaining the entity manager
$entityManager = \Doctrine\ORM\EntityManager::create($conn, $config);   

AnnotationRegistry::registerFile("/usr/local/lib/php/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php");
AnnotationRegistry::registerAutoloadNamespace("Symfony\Component\Validator\Constraint", "/usr/local/lib/php/Doctrine/Symfony");
AnnotationRegistry::registerAutoloadNamespace("MyProject\Annotations", ROOT.DS.'www');

$reader = new AnnotationReader();
AnnotationReader::addGlobalIgnoredName('dummy');

我究竟做错了什么?

更新了带有注释的事件类

事件类

<?php
namespace Entities\Event;
use Doctrine\ORM\Mapping AS ORM;

/**
 * @ORM\Entity
 * @Table(name="events")
 * @Annotations\Event
 */
class Event
{
    /** @ORM\Id @GeneratedValue
     *  @var int
     */
    protected $id;

    /**
     * @ORM\Column(type="string")
     * @Assert\NotEmpty
     * @var string
     */
    protected $name;
}
4

1 回答 1

1

有关定义实体的正确方法,请参阅此文档 原则注释

例如,您需要* @ORM\Entity在您的开场评论中使用。

于 2012-09-14T21:56:43.493 回答