2017-08-02 69 views
1

我是新來的symfony,我正在使用symfony 2.8。 我安裝了FOSUserBundle,它工作得很好,問題是我想添加一個字段到註冊表格中,我遵循FOSUserBundle documentation中的步驟但是沒有任何改變,我沒有收到錯誤。 我不知道我到底在想什麼。 這是我的用戶實體:無法覆蓋FOSUserBundle默認註冊表格

<?php 
// src/AppBundle/Entity/User.php 

namespace AppBundle\Entity; 

use FOS\UserBundle\Entity\User as BaseUser; 
use Doctrine\ORM\Mapping as ORM; 
use Symfony\Component\Validator\Constraints as Assert; 

/** 
* @ORM\Entity 
* @ORM\Table(name="fos_user") 
*/ 
class User extends BaseUser 
{ 
    /** 
    * @ORM\Id 
    * @ORM\Column(type="integer") 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    protected $id; 

    /** 
    * @ORM\Column(type="string", length=255) 
    * 
    * @Assert\NotBlank(message="Please enter your name.", groups={"Registration", "Profile"}) 
    * @Assert\Length(
    *  min=3, 
    *  max=255, 
    *  minMessage="The name is too short.", 
    *  maxMessage="The name is too long.", 
    *  groups={"Registration", "Profile"} 
    *) 
    */ 
    protected $name; 

    public function __construct() 
    { 
     parent::__construct(); 
     // your own logic 
    } 
} 

這是RegistrationType.php:

<?php 
// src/AppBundle/Form/RegistrationType.php 

namespace AppBundle\Form; 

use Symfony\Component\Form\AbstractType; 
use Symfony\Component\Form\FormBuilderInterface; 

class RegistrationType extends AbstractType 
{ 
    public function buildForm(FormBuilderInterface $builder, array $options) 
    { 
     $builder->add('name'); 
    } 

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

    public function getName() 
    { 
     return 'app_user_registration'; 
    } 
} 

的應用程序/配置/ services.yml文件:

parameters: 
    #parameter_name: value 

services: 
    app.form.registration: 
     class: AppBundle\Form\RegistrationType 
     tags: 
      - { name: form.type, alias: app_user_registration } 

這是款與app/config/config.yml中的FOSUserBundle相關:

fos_user: 
    db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel' 
    firewall_name: main 
    user_class: AppBundle\Entity\User 
    registration: 
     form: 
      name: app_user_registration 

我找不到我想要的東西。 謝謝。

+0

你能告訴你的錯誤? –

+0

我沒有收到錯誤,只是沒有任何變化。我沒有在表格中獲得新的領域。 –

+0

你運行過'doctrine:schema:update'嗎? –

回答

2

添加到您form

/** 
* @param OptionsResolverInterface $resolver 
*/ 
public function setDefaultOptions(OptionsResolverInterface $resolver) 
{ 
    $resolver->setDefaults(array(
     'data_class' => 'AppBundle\Entity\User' 
    )); 
} 

如果你正在使用的Symfony < 2.8

# app/config/config.yml 
fos_user: 
    # ... 
    registration: 
     form: 
      type: AppBundle\Form\RegistrationType 

如果你正在使用的Symfony> 2.8

# app/config/config.yml 
fos_user: 
    # ... 
    registration: 
     form: 
      name: AppBundle\Form\RegistrationType 
+0

@YassineYounes你解決了你的問題嗎? –

+0

是的,那就做到了!非常感謝! –

+0

那麼,哪裏錯了? –