php - Stuck in Tutorial Doctrine2: "class Product is not a valid entry or mapped super class" -
trying tutorial: "https://github.com/doctrine/doctrine2/blob/master/docs/en/tutorials/getting-started.rst#id3" when executing "$ php create_product.php orm" error message: "class product not valid entry or mapped super class"
this 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 id " . $product->getid() . "\n"; and bootstrap.php is
<?php // bootstrap.php use doctrine\orm\tools\setup; use doctrine\orm\entitymanager; require_once "vendor/autoload.php"; // create simple "default" doctrine orm configuration 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 entity manager $entitymanager = entitymanager::create($conn, $config); my products.php exact copy in tutolrial , located in /src/project.php
any idea why error-message says product.php not valid entity? , how solve it? best regards, tim van steenbergen
you didn't put @entity annotation, example missing it. try this:
/** * @entity * @table(name="product") */
Comments
Post a Comment