问题
Trying to do the tutorial: "https://github.com/doctrine/doctrine2/blob/master/docs/en/tutorials/getting-started.rst#id3" when executing "$ php create_product.php ORM" I get the error message: "class Product is not a valid entry or mapped super class"
This is 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";
And the bootstrap.php is
<?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);
My Products.php is an exact copy as in the tutolrial and located in /src/Project.php
Any idea why the error-message says that Product.php is not valid entity? And how to solve it? Best regards, Tim van Steenbergen
回答1:
You probably didn't put @Entity annotation, the example is missing it. Try this:
/**
* @Entity
* @Table(name="product")
*/
来源:https://stackoverflow.com/questions/16357843/stuck-in-tutorial-doctrine2-class-product-is-not-a-valid-entry-or-mapped-super