Stuck in Tutorial Doctrine2: “class Product is not a valid entry or mapped super class”

[亡魂溺海] 提交于 2020-01-25 04:05:13

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!