2
votes

I want to integrate doctrine 2 with zf2. I follow this tutorial: http://www.jasongrimes.org/2012/01/using-doctrine-2-in-zend-framework-2/

But i have some problems with doctrine cli.

When i type "project\vendor\doctrine\doctrine-module\bin\doctrine-module orm:generate-proxies", it gives me this message: 'No Metadata Classes to process'.

This is my module.config.php file:

return array(
'controllers' => array(
    'invokables' => array(
        'User\Controller\User' => 'User\Controller\UserController',
    ),
),
'view_manager' => array(
    'template_path_stack' => array(
        'user' => __DIR__ . '/../view',
    ),
),
'router' => array(
    'routes' => array(
        'user' => array(
            'type'    => 'segment',
            'options' => array(
                'route'    => '/user[/:action][/:id]',
                'constraints' => array(
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'id'     => '[0-9]+',
                ),
                'defaults' => array(
                    'controller' => 'User\Controller\User',
                    'action'     => 'userList',
                ),
            ),
        ),
    ),
),

// Doctrine config
'doctrine' => array(
    'driver' => array(
        __NAMESPACE__ . '_driver' => array(
            'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
            'cache' => 'array',
            'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity')
        ),
    'orm_default' => array(
            'drivers' => array(
                __NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
            )
        )
    )
)
);

And this is the \User\src\Entity\Users.php

namespace User\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;

/**
 * @ORM\Entity
 * @ORM\Table(name="user")
 * @property string $username
 * @property int $id
 */
class User
{
/**
 * @ORM\Id 
 * @ORM\GeneratedValue
 * @ORM\Column(type="integer")
 * @var int
 */
private $id;

/**
 * @ORM\Column(type="string")
 */
private $username;
}

If i remove the ORM\ from annotations it gives me the message 'The annotation "@Entity" in class User\Entity\User was never imported. Did you maybe forget to add a "use" statement for this annotation?'

1

1 Answers

2
votes

put namespace User; in the first line of your module.config.php. a namespace should be defined as you use the __NAMESPACE__ constant...