0

我尝试在 Symfony 2.2 中为我的一种形式创建服务:

服务.yml:

tyg_user.settings.form:
    class: Symfony\Component\Form\Form
    factory_method: createNamed
    factory_service: form.factory
    arguments: 
        - tyg_user_settings
        - tyg_user_settings_name
tyg_user.settings.form.type:
    class: TyG\UserBundle\Form\Settings\SettingsFormType
    tags:
        - { name: form.type, alias: tyg_user_settings }
tyg_user.settings.form.handler:
    class: TyG\UserBundle\Form\Settings\SettingsFormHandler
    scope: request
    arguments:
        - @tyg_user.settings.form
        - @request
        - @fos_user.user_manager

SettingsForm.php

<?php

namespace TyG\UserBundle\Form\Settings;

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

class SettingsForm extends AbstractType
{

  public function buildForm(FormBuilder $builder, array $options)
  {
      $builder
        ->add('birthday', 'birthday')
        ->add('email', 'email')
        ->add('showmail')
        ->add('showbirthday')
      ;
  }

  public function getName()
  {
      return 'tyg_user_settings';
  }
}
?>

但是发生了错误:

Could not load type "tyg_user_settings_name

当我通过服务容器获取表单时会发生这种情况:

$this->container->get('tyg_user.settings.form');

我曾经通过 xml 格式创建我的服务,但是当我更改为 yml 格式时,我不知道如何使它工作

4

1 回答 1

2

tyg_user_settings_name正在引用表单类型别名。

如果您希望它引用您应该使用的参数%tyg_user_settings_name%

于 2013-04-05T10:31:34.800 回答