Symfony2: Could not load type “MyType”

心已入冬 提交于 2019-12-04 16:33:29

问题


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

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:

Could not load type "MyType".

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


回答1:


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 }

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



来源:https://stackoverflow.com/questions/7218689/symfony2-could-not-load-type-mytype

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!