Annotations in extended Sonata user class not being read

点点圈 提交于 2019-11-27 18:33:11

问题


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..


回答1:


Delete Application/Sonata/UserBundle/Resources/config/doctrine at first

and later change Entity/User.php and Entity/Group.php to annotation type:

<?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;

}

In the end you should type: php app/console doctrine:schema:update --force and everything should works pretty.




回答2:


In resume, if you use XML, annotations does not rules.

If you delete config/doctrine folder, it will look for annotations, and there, you can put what you want.



来源:https://stackoverflow.com/questions/14042010/annotations-in-extended-sonata-user-class-not-being-read

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!