doudeng2016 2012-09-14 20:51
浏览 34
已采纳

Doctrine 2找不到实体类

I can't get Doctrine to find my entities classes which lays in www/entities/..

I'm keeping getting the error "Fatal error: Class 'Event' not found in /home/dxs/public_html/create-event.php on line 7".. And i feel like i tried almost everything..

The file which im calling is:

create-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() . "
";

Bootstrap.php

<?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';

}

Updated 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');

What am i doing wrong?

Updated event class with annotations

Event class

<?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;
}
  • 写回答

1条回答 默认 最新

  • dongqing7789 2012-09-14 21:56
    关注

    See this doc doctrine annotations for the correct way to define your entity.

    E.g. you need the * @ORM\Entity in your opening comment.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料