Symfony 3 + FOSUser +扩展Form =命名空间错误

时间:2018-11-16 08:34:59

标签: symfony fosuserbundle

使用symfony 3,我尝试扩展this tutorial之后的默认寄存器格式,但出现类似以下的名称空间错误:

Attempted to load class "RegistrationType" from namespace "UserBundle\Form". Did you forget a "use" statement for another namespace?

该问题似乎发生在config.yaml上,如果我添加一行- { resource: "@UserBundle/Resources/Form/RegistrationType.php" },它会解决问题,直到刷新页面为止。我不明白为什么。

这是我的表单扩展名:

<?php

namespace UserBundle\Form;

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

class RegistrationType extends AbstractType

{
public function buildForm(FormBuilderInterface $builder, array $options)

{
    $builder->add('firstname');
    $builder->add('lastname');
}

public function getParent()

{
    return 'FOS\UserBundle\Form\Type\RegistrationFormType';
}

public function getBlockPrefix()

{
    return 'app_user_registration';
}

public function getName()

{
    return $this->getBlockPrefix();
}

}

我的config.yml

# FOSUSerBundle
fos_user:
  db_driver: orm
  firewall_name: api
  user_class: ApiBundle\Entity\User
  from_email:
    address:        %client_mail%
    sender_name:    %client_name%
  registration:
    form:
        type: UserBundle\Form\RegistrationType

我的捆绑包

namespace UserBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class UserBundle extends Bundle
{

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

}

和我的服务

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

0 个答案:

没有答案