2017-04-21 76 views
0

與此article我試圖覆蓋RegisterFormType.php,並沒有看到結果,但Symfony Profiler顯示在表單fos_user_registration中顯示由app_user_registration覆蓋。Symfony FOSUserBundle無法覆蓋表單,沒有效果

首先,我在AppKernel.php:

new FOS\UserBundle\FOSUserBundle(), 
new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'), 
new Application\Sonata\UserBundle\ApplicationSonataUserBundle(), 

services.yml

app.form.registration: 
    class: Application\Sonata\UserBundle\Form\RegistrationFormType 
    tags: 
     - { name: form.type, alias: app_user_registration } 

config.yml:

fos_user: 
    db_driver:  orm # can be orm or odm 
    firewall_name: main 
    user_class:  Application\Sonata\UserBundle\Entity\User 
    use_listener: true 
    group: 
     group_class: Application\Sonata\UserBundle\Entity\Group 
     group_manager: sonata.user.orm.group_manager     # If you're using doctrine orm (use sonata.user.mongodb.group_manager for mongodb) 

    service: 
     user_manager: sonata.user.orm.user_manager      # If you're using doctrine orm (use sonata.user.mongodb.user_manager for mongodb) 
    registration: 
     form: 
      type: app_user_registration 
      #validation_groups: [AppRegistration] 
    profile: 
     form: 
      name: app_user_profile 

的src /應用/索納塔/ UserBundle /表/RegistrationForm.php:

namespace Application\Sonata\UserBundle\Form; 

use ... 

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

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


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

的src /應用/索納塔/ UserBundle /實體/ user.php的:

namespace Application\Sonata\UserBundle\Entity; 

use Sonata\UserBundle\Entity\BaseUser as BaseUser; 

class User extends BaseUser 
{ 
    /** 
    * @var int $id 
    */ 
    protected $id; 

    /** 
    * @var string 
    */ 
    protected $fullName; 

    /** 
    * @return string 
    */ 
    public function getFullName() { 
     return $this->fullName; 
    } 

    /** 
    * @param string $fullName 
    */ 
    public function setFullName($fullName) { 
     $this->fullName = $fullName; 
    } 

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

至於其他的方式(我認爲不正確)試圖重寫RegistrationController.php在我的自定義目錄,改變,因此$form = $this->container->get('app.form.registration')(別名爲我的表格),但我收到錯誤Attempted to call an undefined method named "createView" of class "Application\Sonata\UserBundle\Form\RegistrationFormType。在此之後,我將這個類的父擴展類從ContentAware改爲Controller,並且可以看到表單和新字段,但是在提交接收未知錯誤之後,即使在Profiler中沒有寫出它的名字。

Symfony 2.8.18,FOSUserBundle 1.3.7。感謝您的時間。

+0

解決,config.yml形式的名稱變更爲** **型(儘管在文檔寫的名字發現了它的調試:容器 –

回答

0

你是否在config.yml中更新了FOSUserBundle的配置?

fos_user: 
    # ... 
    registration: 
     form: 
      name: app_user_registration 
+0

是,在添加後上述怎麼現在看起來這個文件片段對不起,忘了一次提到這個文件。 –