2013-05-03 133 views
1

執行「$ php create_product.php ORM」時試圖執行教程:「https://github.com/doctrine/doctrine2/blob/master/docs/en/tutorials/getting-started.rst#id3」我收到錯誤消息:「class Product is不是有效的條目或映射超類」Stuck in Tutorial Doctrine2:「class Product is not a valid entry or mapped super class」

這是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是完全相同的副本,因爲我n的tutolrial和位於/ src/Project.php

任何想法爲什麼錯誤消息說,Product.php是無效的實體?以及如何解決它? 此致敬禮, 蒂姆凡斯滕伯根

回答

1

你可能沒有把@Entity註釋,例子是缺少它。試試這個:

/** 
* @Entity 
* @Table(name="product") 
*/ 
+0

正確!謝謝Zeljko。當教程90%正確時不好。前往下一個bug! – 2013-05-03 12:41:37

+0

下一個錯誤是缺少註釋 – 2013-05-03 12:55:16

+0

我需要更多信息 – Zeljko 2013-05-06 14:39:41