2017-01-24 64 views
2

我試圖使用FOSUserBundle,我按照覆蓋該軟件包的文檔上的說明,但當我嘗試訪問/註冊時,/登錄工程(I沒有覆蓋它):FOSUserBundle覆蓋註冊,但無法加載類型錯誤

Could not load type "app_user_registration" 
500 Internal Server Error - InvalidArgumentException 

配置

Symfony的版本:3.1.7

FOSUserBundle版本:DEV-主

我的文件

應用程序/配置/ services.yml:

services: 
    app.form.registration: 
     class: CoreBundle\Form\Type\RegistrationFormType 
     tags: 
      - { name: form.type, alias: app_user_registration } 

應用程序/配置/ config.yml:

fos_user: 
    db_driver: orm 
    firewall_name: main 
    user_class: CoreBundle\Entity\User 
    registration: 
     form: 
      type: app_user_registration 

的src/CoreBundle /Form/Type/RegistrationFormType.php

<?php 
// src/CoreBundle/Form/Type/RegistrationFormType.php 

namespace CoreBundle\Form\Type; 

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

class RegistrationFormType 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'; 
    } 
} 
?> 

的src/viwa/UserBundle /控制器/ RegistrationController.php:

<?php 
// src/viwa/UserBundle/Controller/RegistrationController.php 

namespace viwa\UserBundle\Controller; 

use Symfony\Component\HttpFoundation\RedirectResponse; 
use FOS\UserBundle\Controller\RegistrationController as BaseController; 

class RegistrationController extends BaseController 
{ 
    // Don't need to change this right now. 
} 
?> 

的src/viwa/UserBundle/viwaUserBundle.php:

<?php 
// src/viwa/UserBundle/viwaUserBundle.php 

namespace viwa\UserBundle; 

use Symfony\Component\HttpKernel\Bundle\Bundle; 

class viwaUserBundle extends Bundle 
{ 
    public function getParent() 
    { 
     return 'FOSUserBundle'; 
    } 
} 

如果需要其他任何事情來幫助我,我編輯我的帖子。

希望任何人都可以幫助我。

+1

在你的config.yml中,不是使用別名app_user_resitration,而是使用CoreBundle \ Form \ Type \ RegistrationFormType。你的CoreBundle/Form/Type/RegistrationFormType中的getParent()應該返回''FOS \ UserBundle \ Form \ Type \ RegistrationFormType'。如果我看到更多將再次評論 – pogeybait

回答

3

config.yml文件應該是:

fos_user: 
    db_driver: orm 
    firewall_name: main 
    user_class: CoreBundle\Entity\User 
    registration: 
     form: 
      type: CoreBundle\Form\Type\RegistrationFormType 

在你src/CoreBundle/Form/Type/RegistrationFormType.phpgetParent()功能應該是:

public function getParent() 
{ 
    return 'FOS\UserBundle\Form\Type\RegistrationFormType'; 
} 
+0

謝謝!這解決了我的問題,但我不明白爲什麼?在Symfony文檔中,這些地方沒有命名空間 – Angelo

1

你可能閱讀的文檔 '的1.3.x /電流',這默認打開。 如果您切換到'2.0/master',您將選擇正確版本的文檔。

+0

這是一個很好的建議,但對於未來的用戶來說,如果您在答案中也包含問題的解決方案,可能會有所幫助。 – mickadoo

相關問題