After copy-pasting the example as is on the page I am getting this error:
[Doctrine\ORM\Mapping\MappingException]
No identifier/primary key specified for Entity "Product". Every Entity must have an identifier/primary key.
I searched a bit and found out that an entity annotation was missing from the code so I ended up with this code:
<?php
// bootstrap.php
/**
* @Entity
* @Table(name="Product")
* property int $id
* property string $name
*/
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);
// or if you prefer yaml or XML
//$config = Setup::createXMLMetadataConfiguration(array(__DIR__."/config/xml"), $isDevMode);
//$config = Setup::createYAMLMetadataConfiguration(array(__DIR__."/config/yaml"), $isDevMode);
// database configuration parameters
$conn = array(
'driver' => 'pdo_sqlite',
'path' => __DIR__ . '/db.sqlite',
);
// obtaining the entity manager
$entityManager = EntityManager::create($conn, $config);
The product creator is also taken from the tutorial:
// 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() . "
";
The Product is defined here:
<?php
/**
* @Entity
* @Table(name="Product")
* property int $id
* property string $name
*/
// src/Product.php
class Product
{
/**
* @var integer $id
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
*/
protected $name;
public function getId()
{
return $this->id;
}
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
}
}
I also tried the instructions here though they did not give me any result. I am very new to doctrine so do you have any ideas on what to try next?