问题
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