This form should not contain extra fields
y no me deja guardar. alguna idea de que pueda ser esto?
adjunto el codigo de lo que tengo , muchas gracias de antemano.
Entidad
Código:
Metodos Usercontroller.php donde crea la forma que inserta/** * @ORM\Entity * @ORM\Table(name="admin_user") */ class User implements UserInterface { /** * @var integer $id * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @ORM\Column(type="string", length=255) */ protected $username; /** * @ORM\Column(name="password", type="string", length=255) */ protected $password; /** * @ORM\Column(name="salt", type="string", length=255) */ protected $salt; /** * se utilizó user_roles para no hacer conflicto al aplicar ->toArray en getRoles() * @ORM\ManyToMany(targetEntity="Role") * @ORM\JoinTable(name="user_role", * joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}, * inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")} * ) */ protected $user_roles; public function __construct() { $this->user_roles = new \Doctrine\Common\Collections\ArrayCollection(); } /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set username * * @param string $username */ public function setUsername($username) { $this->username = $username; } /** * Get username * * @return string */ public function getUsername() { return $this->username; } /** * Set password * * @param string $password */ public function setPassword($password) { $this->password = $password; } /** * Get password * * @return string */ public function getPassword() { return $this->password; } /** * Set salt * * @param string $salt */ public function setSalt($salt) { $this->salt = $salt; } /** * Get salt * * @return string */ public function getSalt() { return $this->salt; } /** * Add user_roles * * @param Login\LoginBundle\Entity\Role $userRoles */ public function addRole(\Login\LoginBundle\Entity\Role $userRoles) { $this->user_roles[] = $userRoles; } public function setUserRoles($roles) { $this->user_roles = $roles; } /** * Get user_roles * * @return Doctrine\Common\Collections\Collection */ public function getUserRoles() { return $this->user_roles; } /** * Get roles * * @return Doctrine\Common\Collections\Collection */ public function getRoles() { return $this->user_roles->toArray(); //IMPORTANTE: el mecanismo de seguridad de Sf2 requiere ésto como un array } /** * Compares this user to another to determine if they are the same. * * @param UserInterface $user The user * @return boolean True if equal, false othwerwise. */ public function equals(UserInterface $user) { return md5($this->getUsername()) == md5($user->getUsername()); } /** * Erases the user credentials. */ public function eraseCredentials() { } /** * Add user_roles * * @param \Login\LoginBundle\Entity\Role $userRoles * @return User */ public function addUserRole(\Login\LoginBundle\Entity\Role $userRoles) { $this->user_roles[] = $userRoles; return $this; } /** * Remove user_roles * * @param \Login\LoginBundle\Entity\Role $userRoles */ public function removeUserRole(\Login\LoginBundle\Entity\Role $userRoles) { $this->user_roles->removeElement($userRoles); } }
Código:
forma :private function createCreateForm(User $entity) { $form = $this->createForm(new UserType(), $entity, array( 'action' => $this->generateUrl('admin_user_create'), 'method' => 'POST', )); $form->add('submit', 'submit', array('label' => 'Create')); return $form; } /** * Displays a form to create a new User entity. * * @Route("/new", name="admin_user_new") * @Method("GET") * @Template() */ public function newAction() { $entity = new User(); $form = $this->createCreateForm($entity); return array( 'entity' => $entity, 'form' => $form->createView(), ); }
Código:
class UserType extends AbstractType { /** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('username') ->add('password') //->add('salt') //No necesitamos que salt sea mostrado ------------ ->add('user_roles') ; } /** * @param OptionsResolverInterface $resolver */ public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( 'data_class' => 'Login\LoginBundle\Entity\User' )); } /** * @return string */ public function getName() { return 'login_loginbundle_user'; } }