Integration Doctrine 2 in Zend Framework 2

I try to integrate Doctrine 2 into Zend Framework 2 - which works, except for the command line interface.

I use the command vendor/bin/doctrine-module orm:schema-tool:create

First I had in my model class:

<?php
namespace Application\Entity;
 
/**
* @Entity
* @ORM\Table(name="product")
* @property int $id
* @property string $title
* @property string $text
*/
class Product {}

I got this as response:

[Doctrine\Common\Annotations\AnnotationException]
  [Semantical Error] The annotation "@Entity" in class Application\Entity\Product was never imported. Did you maybe forget to add a "use" statement for this annotation?

So I searched on Google and did the following:

<?php
namespace Application\Entity;
 
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\Entity;
 
/**
* @Entity
* @ORM\Table(name="posts")
* @property int $id
* @property string $title
* @property string $text
*/
class Product

However, now I just get

No Metadata Classes to process.

What am I doing wrong?

It seems that you aint using Doctrine 2’s annotation properly. I dont know about Doctrine’s annotation, and I honestly think you should not use annotation at all, instead switch to XML or YAML. Annotations in PHP is a very bad idea, because they aint language integrated and instead are placed in PHP comments. This makes your comments more than just comments, which are harder to read and maintain. Read this article and you will understand why:

So I followed your advice and started to use the YAML annotations (that is how I used to work in doctrine 1), but no luck yet.

I am trying to follow the “getting started” tutorial of the official Doctrine site (http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/getting-started.html) .

I am trying to make the YAML configuration generate my classes + databasetables inside a zend framework 2 enviroment.

I copied both the Product.php and the Product.dcm.yml in the right places, but if I run

vendor/bin/doctrine orm:generate-entities module/Application/src/Application/Entity/

from the root of the zend framework project, I get:

“Invalid mapping file ‘Product.dcm.yml’ for class ‘Product’.”

I copied those 2 files perfectly, so I do not understand what is going wrong, could somebody help me?

Just for good order, my 2 files:

config/yaml/Product.dcm.yml

Product:
type: entity
table: products
id:
id:
type: integer
generator:
strategy: AUTO
fields:
name:
type: string

<?php // src/Product.php class Product { /** * @var int */ 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;
}

}

Working for two days on this, still no working Doctrine. :cry:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.