2013-10-23 63 views
2

我下面的FOSUserBundle docs的覆蓋形式後得到一個錯誤。我得到的錯誤是:FOSUserBundle重寫默認窗體和獲取InvalidArgumentException

爲服務「scheduler_user.registration.form.type」指定的類型名稱與實際名稱不匹配。預計 「scheduler_user_registration」,給予 「fos_user_registration」

以下是相關文件:

RegistrationFormType.php

<?php 
// src/Scheduler/UserBundle/Form/Type/RegistrationFormType.php 

namespace Scheduler\UserBundle\Form\Type; 

use Symfony\Component\Form\FormBuilderInterface; 
use FOS\UserBundle\Form\Type\RegistrationFormType as BaseType; 

class RegistrationFormType extends BaseType 
{ 
    public function buildForm(FormBuilderInterface $builder, array $options) 
    { 
     parent::buildForm($builder, $options); 

     // add your custom field 
     $builder->add('firstname'); 
     $builder->add('lastname'); 
    } 

    public function getFirstname() 
    { 
     return 'scheduler_user_registration'; 
    } 

    public function getLastname() 
    { 
     return 'scheduler_user_registration'; 
    } 
} 

user.php的

<?php 
// src/Scheduler/UserBundle/Entity/User.php 

namespace Scheduler\UserBundle\Entity; 

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

/** 
* @ORM\Entity 
* @ORM\Table(name="users") 
*/ 
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="Enter your first name.", groups={"Registration", "Profile"}) 
    */ 
    protected $firstname; 

    /** 
    * @ORM\Column(type="string", length=255) 
    * 
    * @Assert\NotBlank(message="Enter your last name.", groups={"Registration", "Profile"}) 
    */ 
    protected $lastname; 

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

config.yml

# app/config/config.yml 

# ... 

# FOS User Bundle 
fos_user: 
    db_driver: orm 
    firewall_name: main 
    user_class: Scheduler\UserBundle\Entity\User 
    registration: 
     form: 
     type: scheduler_user_registration 

services.yml

# src/Scheduler/UserBundle/Resources/config/services.yml 
services: 
    scheduler_user.registration.form.type: 
     class: Scheduler\UserBundle\Form\Type\RegistrationFormType 
     arguments: [%fos_user.model.user.class%] 
     tags: 
      - { name: form.type, alias: scheduler_user_registration } 

回答

0

表單類型不需要getFirstnamegetLastname方法。

刪除其中的一個,另一個重命名爲getName

該方法不是表單字段的getter。它只是指定表單的名稱。