【问题标题】:Auto generate annotations自动生成注释
【发布时间】:2011-07-18 05:22:03
【问题描述】:

我该怎么做? 我尝试运行:

app/console doctrine:generate:entities BlogWebBundle

但我得到的课程没有注释(cmets 中的“@orm ...”)
就像在这个例子中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;
}

我有这个 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: {  }

并生成实体:

<?php

namespace Blog\WebBundle\Entity;

/**
 * Blog\WebBundle\Entity\Posts
 */
class Posts
{
    /**
     * @var integer $id
     */
    private $id;

    /**
     * @var string $title
     */
    private $title;

    /**
     * @var 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;
    }
}

【问题讨论】:

    标签: php doctrine-orm symfony


    【解决方案1】:

    当您已经在 YAML 文档中拥有映射时,为什么还要让您的实体具有注释。我想也许这就是为什么它不会在您生成的实体中添加注释?

    (我不确定,我不生成实体)

    【讨论】:

    • 因为看不到 DB 结构或 YML 文件。但我已经修复了它,通过在生成器中添加一些类似 $this-&gt;setAnnotations(true) 的想法
    【解决方案2】:

    你可以编辑vendor/symfony/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php

    $entityGenerator-&gt;setGenerateAnnotations(false); 更改为true

    【讨论】:

      猜你喜欢
      • 2016-05-05
      • 2012-06-23
      • 2012-10-27
      • 2012-09-16
      • 2018-06-06
      • 1970-01-01
      • 1970-01-01
      • 2016-05-24
      • 2012-10-25
      相关资源
      最近更新 更多