How do I use the doctrine's entity generator?

0

I'm trying to use doctrine in a project. but I'm having difficulty getting the entity generator once the database is ready and I would like the doctrine to create entities from it.

  

bootstrap.php

<?php
// o Autoload é responsável por carregar as classes sem necessidade de incluí-las previamente
require_once "vendor/autoload.php";

// o Doctrine utiliza namespaces em sua estrutura, por isto estes uses
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping;

//onde irão ficar as entidades do projeto? Defina o caminho aqui
$entidades = array("entity/");
$isDevMode = true;

// configurações de conexão. Coloque aqui os seus dados
$dbParams = array(
'driver'   => 'pdo_mysql',
'host'     => 'localhost',
'user'     => 'root',
'password' => 'senhadodb',
'dbname'   => 'LojaVirtual',
);

//setando as configurações definidas anteriormente
$config = Setup::createAnnotationMetadataConfiguration($entidades, $isDevMode);

//criando o Entity Manager com base nas configurações de dev e banco de dados
$entityManager = EntityManager::create($dbParams, $config);

I'm trying to create entities with the following code:

$cmf = new Doctrine\ORM\Tools\DisconnectedClassMetadataFactory();
$cmf->setEntityManager($entityManager); // $em is EntityManager instance
$metadata = $cmf->getAllMetadata();
$generator = new \Doctrine\ORM\Tools\EntityGenerator();
$generator->setGenerateAnnotations(true);
$generator->setGenerateStubMethods(true);
$generator->setRegenerateEntityIfExists(true);
$generator->setUpdateEntityIfExists(false);
$generator->generate($metadata, 'entity');

I've already tried this:

$classes = $entityManager->getMetadataFactory()->getAllMetadata();
$generator = new EntityGenerator();
$generator->setGenerateAnnotations(true);
$generator->setGenerateStubMethods(true);
$generator->setRegenerateEntityIfExists(false);
$generator->setUpdateEntityIfExists(true);
$generator->generate($classes, 'entity/');

I've never worked with doctrine before, searched the documentation and on several sites and found no way to make it work. I found some tutorials explaining to do for Command Line but they were not useful either.

I hope someone can tell me what's wrong and / or what I should do to generate the entities from a ready db.

    
asked by anonymous 01.12.2014 / 11:59

0 answers