在教程Doctrine2中存在:“类产品不是有效的条目或映射的超类” [英] Stuck in Tutorial Doctrine2: "class Product is not a valid entry or mapped super class"
问题描述
尝试做教程: https://github.com/doctrine/doctrine2/blob/master/docs/en/tutorials/getting-started.rst#id3 执行$ php create_product.php ORM时,我收到错误信息:class Product is not a valid entry or mapped super class
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"
这是create_product.php
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";
而且bootstrap.php是
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);
我的Products.php是一个精确的副本,如在tutolrial中,位于/src/Project.php
My Products.php is an exact copy as in the tutolrial and located in /src/Project.php
任何想法为什么错误消息说Product.php不是有效的实体?又如何解决呢?
最好的问候,
Tim van Steenbergen
Any idea why the error-message says that Product.php is not valid entity? And how to solve it? Best regards, Tim van Steenbergen
推荐答案
你可能没有把@Entity注释,例子是缺少它。尝试这样:
You probably didn't put @Entity annotation, the example is missing it. Try this:
/**
* @Entity
* @Table(name="product")
*/
这篇关于在教程Doctrine2中存在:“类产品不是有效的条目或映射的超类”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!