Symfony2:无法加载类型“MyType"; [英] Symfony2: Could not load type "MyType"

查看:21
本文介绍了Symfony2:无法加载类型“MyType";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个新的字段类型并将其添加到 Symfony 2 中的表单类中.

I am trying to create a new field type and add it to a form class in Symfony 2.

我创建了一个名为 MyType 的类(用于测试目的),当我想将它添加到表单类时,出现错误:

I have created a class called MyType (for testing purpose) and when I want to add it to a form class I get the error:

无法加载类型MyType".

Could not load type "MyType".

我想我必须告诉 Symfony 加载那个类型,但我不知道怎么做!

I guess I must tell Symfony to load that type, but I don't know how!

推荐答案

您已经在 config.yml 的服务部分注册了您的表单

You have register your form in the section services of your config.yml

services:
   my_type_form:
      class: sf\MyTypeBundle\Form\MyType
      tags:
         -  { name: form.type }

然后你可以从你的控制器中使用名称my_type_form"调用它.

Then you can call it from your controller with the name "my_type_form".

这篇关于Symfony2:无法加载类型“MyType";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆