我无法让 Doctrine 找到位于 www/entities/..

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

我调用的文件是:

创建事件.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";

bootstrap
<?php
use Doctrine\ORM\EntityRepository;

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

{

    require_once 'bootstrap_doctrine.php';

}

bootstrap
<?php
use Doctrine\ORM\EntityRepository;

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

    require_once 'bootstrap_doctrine.php';

}

更新的 bootstrap Doctrine
 <?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;
}

最佳答案

请参阅此文档
doctrine annotations
以正确方式定义您的实体。

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

关于php - Doctrine 2 找不到实体类,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12431806/

10-16 18:17