Auto generate annotations
How can i do this? I try to run:
app/console doctrine:generate:entities BlogWebBundle
But i get class without annotations ("@orm ..." in comments)
Like in this example http://symfony.com/doc/2.0/book/doctrine/orm/overview.html// Sensio/HelloBundle/Entity/User.php
namespace Sensio\HelloBundle\Entity;
/**
* @orm:Entity
*/
class User
{
/**
* @orm:Id
* @orm:Column(type="integer")
* @orm:GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @orm:Column(type="string", length="255")
*/
protected $name;
}
I have this yaml
Blog\WebBundle\Entity\Posts:
type: entity
table: posts
fields:
id:
id: true
type: integer
unsigned: false
nullable: false
generator:
strategy: IDENTITY
title:
type: string
length: 255
fixed: false
nullable: false
content:
type: text
nullable: false
uid:
type: integer
unsigned: false
nullable: false
lifecycleCallbacks: { }
And the Entity is generated:
<?php
namespace Blog\WebBundle\Entity;
/**
* Blog\WebBundle\Entity\Posts
*/
class Posts
{
/**
* @var integer $id
*/
private $id;
/**
* @var string $title
*/
private $title;
/**
* @va开发者_开发技巧r text $content
*/
private $content;
/**
* @var integer $uid
*/
private $uid;
/**
* Get id
*
* @return integer $id
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* @param string $title
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* Get title
*
* @return string $title
*/
public function getTitle()
{
return $this->title;
}
/**
* Set content
*
* @param text $content
*/
public function setContent($content)
{
$this->content = $content;
}
/**
* Get content
*
* @return text $content
*/
public function getContent()
{
return $this->content;
}
/**
* Set uid
*
* @param integer $uid
*/
public function setUid($uid)
{
$this->uid = $uid;
}
/**
* Get uid
*
* @return integer $uid
*/
public function getUid()
{
return $this->uid;
}
}
You can edit vendor/symfony/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php
Change $entityGenerator->setGenerateAnnotations(false);
to true
Why would you want your entity to have annotations when you already have your mapping in a YAML document. I think maybe this is why it doesn't add annotations into your generated entities?
(I don't know for sure, I don't generate my entities)
精彩评论