Creating Custom Field with FOSUserBundle

て烟熏妆下的殇ゞ 提交于 2019-12-10 08:43:55

问题


I want to add an address and telephone number using FOSUserBundle. How can I add a Custom fields, with FOSuserBundle, to have a profile that contains address and telephone number....


回答1:


Create an own user bundle and in the MyCompanyUserBundle.php you set

public function getParent(){
        return 'FOSUserBundle';
}

Then in your new UserBundle you create a User entity and let it extend from the base user of the FOS user bundle:

use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

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

    public function __toString(){
        return $this->firstname . ' ' . $this->lastname . ' (' . $this->email . ')';
    }

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }



}

EDIT

Set the user in the config as well:

fos_user:
        db_driver: orm
        firewall_name: main
        user_class: MyCompany\UserBundle\Entity\User



回答2:


the problem is in : when i follow the symfony documentation:https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.md in step a) Doctrine ORM User class i have created a folder doctrine contains User.orm.yml:

src/Acme/UserBundle/Resources/config/doctrine/User.orm.yml

Acme\UserBundle\Entity\User: type: entity table: fos_user id: id: type: integer generator: strategy: AUTO

this file crush any update in your entities and update of your database shemea .The solution is to delete this folder.




回答3:


You don't have to add custom fields but you have to create your own user model.

Read the doc, all is explained: https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.md#step-3-create-your-user-class



来源:https://stackoverflow.com/questions/21854890/creating-custom-field-with-fosuserbundle

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