简体   繁体   中英

Symfony2, Sonata : Getting rid of unnecessary fields in UserBundle

I would like to not use some default fields giving by the Sonata User bundle. Such as facebook, gplus or twitters fields.

I extended the SonataUserBundle in Application\\Sonata\\UserBundle with Easy-Extends.

And created a new User entity extenting the BaseUser :

class User extends BaseUser

I deleted the xml doctrine config since i'm using annotations.

So it does recognize my custom fields such as "city" and "address".

But i have all the fields from BaseUser, how can i get rid of unnecessary fields?

<?php
namespace Application\Sonata\UserBundle\Entity;

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

/**
 * @ORM\Entity
 * @ORM\Table(name="fos_user_user")
 */
class User extends BaseUser
{

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

    /**
     * @ORM\Column(type="string", length=64, nullable=false, name="city")
     */
    protected $city;

    /**
     * @ORM\Column(type="string", length=255, nullable=false, name="address")
     */
    protected $address;

}

Sonata UserBundle seems to extend FOSUserBundle:

use FOS\UserBundle\Entity\User as AbstractedUser;
use Sonata\UserBundle\Model\UserInterface;

abstract class User extends AbstractedUser implements UserInterface

So, I think you should be able to do the same; instead of extending Sonata User, extend FOSUser and implement the UserInterface. That way you should be able to get rid of the undesired fields, as long as they are in sonata's User model.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM