学说生成模型。元数据配置

时间:2015-07-23 12:11:28

标签: codeigniter orm configuration doctrine

我在CodeIgniter控制器中使用Doctrine.php中的Doctrine生成方法生成实体:

function generate_classes(){     

$this->em->getConfiguration()
         ->setMetadataDriverImpl(
            new DatabaseDriver(
                    $this->em->getConnection()->getSchemaManager()
            )
);

$cmf = new DisconnectedClassMetadataFactory();
$cmf->setEntityManager($this->em);
$metadata = $cmf->getAllMetadata();     
$generator = new EntityGenerator();

$generator->setUpdateEntityIfExists(true);
$generator->setGenerateStubMethods(true);
$generator->setGenerateAnnotations(true);
$generator->generate($metadata, APPPATH."models/Entities");

 }

生成的Entity具有以下语法:

use Doctrine\ORM\Mapping as ORM;

/**
 * Users
 *
* @ORM\Table(name="users")
* @ORM\Entityz
*/
class Users
{
/**
 * @var integer
 *
 * @ORM\Column(name="idusers", type="integer", nullable=false)
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="IDENTITY")
 */
 private $idusers;

/**
 * @var string
 *
 * @ORM\Column(name="first_name", type="string", length=45,      nullable=true)
 */
private $firstName;

/**
 * @var string
 *
 * @ORM\Column(name="last_name", type="string", length=45, nullable=true)
 */

现在调用这些实体形成我的模型不起作用。该模型没有找到该实体。手动将语法更改为以下代码示例后,我让它工作:

use Doctrine\ORM\Mapping as ORM;

/**
* Users
*
* @Entity @Table(name="users")
*/
class Users
{
/**
 * @var integer
 *
 * @Column(name="idusers", type="integer", nullable=false)
 * @Id
 * 
 */
private $idusers;

/**
 * 
 * @GeneratedValue 
 * @Column(name="first_name", type="string", length=45,     nullable=true)
 */
private $firstName;

现在一切正常! 我不打算手动更改每个实体。 如何配置Doctrine以使用正确的语法生成实体。正如他们的教程中所使用的那样? http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/getting-started.html

Noob问题。请帮忙!

1 个答案:

答案 0 :(得分:0)

找到解决方案:  在application / vendor / doctrine / orm / lib / Doctrine / ORM / Tools / EntityGenerator.php中更改了以下构造函数:

public function __construct()
{
    if (version_compare(\Doctrine\Common\Version::VERSION, '2.2.0-DEV', '>=')) {
        $this->annotationsPrefix = 'ORM\\';
    }
}

要:

public function __construct()
{
    if (version_compare(\Doctrine\Common\Version::VERSION, '2.2.0-DEV', '>=')) {
        $this->annotationsPrefix = '';
    }
}