无法加载类型“文字”在第91行的vendor / symfony / symfony / src / Symfony / Component / Form / FormRegistry.php中 [英] Could not load type "text" in vendor/symfony/symfony/src/Symfony/Component/Form/FormRegistry.php at line 91

查看:177
本文介绍了无法加载类型“文字”在第91行的vendor / symfony / symfony / src / Symfony / Component / Form / FormRegistry.php中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Symfony标准版,并且所有内容都在 Symfony2.X 版本中运行,直到我将其更新到 3.0.x-dev



即使在新版本中,除了在控制器中给我一个错误的页面外,一切都可以正常工作:


无法加载类型text500内部服务器错误 -
InvalidArgumentException


  1. in vendor / symfony / symfony / src / Symfony / Component / Form / FormRegistry.php at
    line 91

  2. at FormRegistry - > getType('text')in vendor / symfony /symfony/src/Symfony/Component/Form/FormFactory.php at
    line 84

  3. 在FormFactory - > createNamedBuilder('flag','text',null,array( ))in vendor / symfony / symfony / src / Symfony / Component / Form / FormBuilder.php
    在第106行

  4. 在FormBuilder - > create('flag','text ',array())in vendor / symfony / symfony / src / Symfony / Component / Form / FormBuil der.php at
    line 267

  5. 在FormBuilder中 - > resolveChildren()在vendor / symfony / symfony / src / Symfony / Component / Form / FormBuilder.php at
    行215

  6. 在FormBuilder - > getForm()在src / MyProject / FrontOfficeBundle / Controller / ChallengeController.php在
    行418

  7. ol>

在控制器中,我使用了以下代码:

  $ form = $ this-> createFormBuilder()
- > add(flag,text)
- > add(validate,button)
- > getForm();

即使我删除第一个添加(flag,text),错误切换为:
$ b


无法加载类型按钮


所以我认为问题出在 getForm()方法中。我厌倦了方法 createFormBuilder()需要一个参数,所以我试图传递一个对象标志,它有很多参数(flag,validate,...)。



这个问题并没有改变,就好像这个版本的语法改变了,但是当我验证了 documentation ,我的语法没有发现任何问题。

表单的版本是 3.0-dev 。我在github项目中验证了它,这些文件是最新的。我用

 作曲家更新

我删除了缓存和日志文件,但存在问题。



感谢您的帮助,并对我的英文不好。

解决方案

读取UPGRADE-3.0.md 该文件告诉你如何将代码从2.x改为3.0,而不是如何升级symfony代码库。不幸的是,它没有提及如何处理这个表单问题。



您将遇到的问题在 [UPGRADE-2.8 .md](https://github.com/symfony/symfony/blob/2.8/UPGRADE-2.8.md),由表单名称 text / 按钮被弃用,以支持其完全限定的类名称(FQCN)。

<强>从UPGRADE-2.8.md



类型名称已被弃用,并将在Symfony 3.0中删除。而不是通过名称引用类型,而应该使用完全限定的类名称(FQCN)引用它们。在PHP 5.5或更高版本中,您可以使用class常量:

之前:

<$ p $ ('''','text')
- > add('age','整数')
- > getForm();

后:

 使用Symfony \Component\Form\Extension\Core\Type\IntegerType; 
使用Symfony \Component\Form\Extension\Core\Type\TextType;
$ b $ form $ this-> createFormBuilder()
- > add('name',TextType :: class)
//或 - > add('名称',Symfony \ Component\Form\Extension\Core\Type\TextType)
- > add('age',IntegerType :: class)
//或 - > ;添加('age',Symfony \ Component \Form\Extension\Core\Type\IntegerType)
- > getForm();

...它会告诉你更多......


I'm using Symfony Standard Edition, and everything work in the version of Symfony2.X until I update it to the 3.0.x-dev.

Even in the newer version, everything works except a page that give me an error in the Controller:

Could not load type "text" 500 Internal Server Error - InvalidArgumentException

  1. in vendor/symfony/symfony/src/Symfony/Component/Form/FormRegistry.php at line 91
  2. at FormRegistry ->getType ('text') in vendor/symfony/symfony/src/Symfony/Component/Form/FormFactory.php at line 84
  3. at FormFactory ->createNamedBuilder ('flag', 'text', null, array()) in vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php at line 106
  4. at FormBuilder ->create ('flag', 'text', array()) in vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php at line 267
  5. at FormBuilder ->resolveChildren () in vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php at line 215
  6. at FormBuilder ->getForm () in src/MyProject/FrontOfficeBundle/Controller/ChallengeController.php at line 418

In the Controller I used this code:

$form = $this->createFormBuilder()
->add("flag","text")
->add("validate","button")
->getForm();

Even if I delete the first add("flag","text"), the error switch to:

Could not load type "button"

So I think that the problem is in the method getForm(). I gassed that the method createFormBuilder() need a parameter so I tried to pass an object Flag which it have many arguments (flag,validate,...).

The problem didn't change it's like the syntax was changed in this version but when I verified the documentation, I didn't found any problems in my syntax.

The form's version is 3.0-dev. I verified it in the github project and those files are the latests. I used

composer update

And I removed the cache and the logs files but problem exists.

Thanks for your help and sorry for my bad english.

解决方案

What @CarlosGranados means by read the UPGRADE-3.0.md is to read the file that tells you how you would need to change your code from that of 2.x to 3.0 rather than how to upgrade the symfony code base. Unfortunately it doesn't mention how to deal with this forms issue.

The issue that you will be facing is covered in the [UPGRADE-2.8.md](https://github.com/symfony/symfony/blob/2.8/UPGRADE-2.8.md) and is due to the form names text/button being deprecated in favour of their fully-qualified class name (FQCN).

From UPGRADE-2.8.md

Type names were deprecated and will be removed in Symfony 3.0. Instead of referencing types by name, you should reference them by their fully-qualified class name (FQCN) instead. With PHP 5.5 or later, you can use the "class" constant for that:

Before:

$form = $this->createFormBuilder()
    ->add('name', 'text')
    ->add('age', 'integer')
    ->getForm();

After:

use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\TextType;

$form = $this->createFormBuilder()
    ->add('name', TextType::class)
    // or ->add('name', Symfony\Component\Form\Extension\Core\Type\TextType)
    ->add('age', IntegerType::class)
    // or ->add('age', Symfony\Component\Form\Extension\Core\Type\IntegerType)
    ->getForm();

... and it goes on to tell you a bunch more ...

这篇关于无法加载类型“文字”在第91行的vendor / symfony / symfony / src / Symfony / Component / Form / FormRegistry.php中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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