尝试做教程:https ://github.com/doctrine/doctrine2/blob/master/docs/en/tutorials/getting-started.rst#id3
执行时$ php create_product.php ORM
我收到错误消息:
类产品不是有效的条目或映射的超类
这是 create_product.php
<?php
// create_product.php
require_once "bootstrap.php";
$newProductName = $argv[1];
$product = new Product();
$product->setName($newProductName);
$entityManager->persist($product);
$entityManager->flush();
echo "Created Product with ID " . $product->getId() . "\n";
bootstrap.php 是
<?php
// bootstrap.php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
require_once "vendor/autoload.php";
// Create a simple "default" Doctrine ORM configuration for Annotations
$isDevMode = true;
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src"), $isDevMode);
// database configuration parameters
$conn = array(
'driver' => 'pdo_mysql',
'dsn' => 'mysql:dbname=doctrine2;host=any.where.nl',
'driver_options' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
)
// 'driver' => 'pdo_sqlite',
// 'path' => __DIR__ . '/db.sqlite',
);
// obtaining the entity manager
$entityManager = EntityManager::create($conn, $config);
我的 Products.php 与教程中的完全相同,位于/src/Project.php
知道为什么错误消息说 Product.php 不是有效实体吗?以及如何解决?最好的问候,蒂姆·范·斯滕伯格