6

I extended the user bundle from the Sonata project with Sonata EasyExtends bundle. It is placed under src/Application/Sonata/UserBundle by default

Now I want to customize the extended class and add some fields. I notice though that annotations are not being processed, I need to define the mappings in src/Application/Sonata/UserBundle/Resources/config/doctrine/User.orm.xml

Is there any way to make use of the annotations instead of the XML file? I think it will solve a lot of my problems with referencing the user class, as now the command

php app/console doctrine:schema:update --force

doesnt seem to recognize the annotations..

4

2 に答える 2

10

最初にApplication/Sonata / UserBundle / Resources / config/doctrineを削除します

その後、Entity/User.phpとEntity/Group.phpを注釈タイプに変更します。

<?php

namespace Application\Sonata\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Sonata\UserBundle\Entity\BaseUser as BaseUser;

/**
 * User
 *
 * @ORM\Table(name="fos_user_user")
 * @ORM\Entity
 */

class User extends BaseUser
{

    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(type="string", length=127)
     */
    protected $test;
}
<?php

namespace Application\Sonata\UserBundle\Entity;

use Sonata\UserBundle\Entity\BaseGroup as BaseGroup;
use Doctrine\ORM\Mapping as ORM;

/**
 * Group
 *
 * @ORM\Table(name="fos_user_group")
 * @ORM\Entity
 */
class Group extends BaseGroup
{

    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

}

最後に、次のように入力する必要があります。php app / console doctrine:schema:update --forceすると、すべてが正常に機能するはずです。

于 2013-01-02T12:34:22.517 に答える
-1

履歴書で XML を使用すると、注釈は規則になりません。

config/doctrine フォルダーを削除すると、注釈が検索され、そこに必要なものを配置できます。

于 2015-02-28T08:48:17.597 に答える