Php 原则2可以';找不到实体类
我无法让Doctrine找到位于www/entities/中的实体类 我一直收到错误“致命错误:在第7行的/home/dxs/public_html/create-Event.php中找不到类'Event'。”。。我觉得我几乎什么都试过了 我调用的文件是: create-event.php:Php 原则2可以';找不到实体类,php,orm,doctrine,doctrine-orm,Php,Orm,Doctrine,Doctrine Orm,我无法让Doctrine找到位于www/entities/中的实体类 我一直收到错误“致命错误:在第7行的/home/dxs/public_html/create-Event.php中找不到类'Event'。”。。我觉得我几乎什么都试过了 我调用的文件是: create-event.php: 请参阅此文档 以获取定义实体的正确方法 例如,您需要在开始评论中使用*@ORM\Entity。我将其包含在我的事件实体类命名空间实体中;使用条令\ORM\Mapping作为ORM;感谢添加实体-最好也将新的
请参阅此文档
以获取定义实体的正确方法
例如,您需要在开始评论中使用*@ORM\Entity
。我将其包含在我的事件实体类命名空间实体中;使用条令\ORM\Mapping作为ORM;感谢添加实体-最好也将新的错误消息添加到更新后,以便观众清楚地看到正在解决的问题。我遵循了条令注释,但仍然收到错误:Entities\Event不是有效的实体或映射的超类。'in/usr/local/lib/php/Doctrine/ORM/Mapping/MappingException.php:147这可能不是实际的解决方案,但是如果您想使用验证约束(@Assert\NotEmpty),您需要在项目中包含它们。例如,您使用该行的Doctine文档具有“将Symfony\Component\Validation\Constraints用作Assert”;在您的情况下,您可能应该删除@Assert,直到它在您的自动加载器中正常工作。我看到它在您的自动加载器中,但您错过了实体的use语句。我让它正常工作,结果表明,我的服务器在错误的文件夹中查找实体,我在两个地方有一个实体文件夹。。但是谢谢你的邀请help@Saggo你是怎么计算出来的?我也有同样的问题,我尝试使用--path参数…
<?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
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;
}