【问题标题】:How to fix form DeprecatedWarning(s) before the update from Symfony 2.8 to Symfony 3.x?如何在从 Symfony 2.8 更新到 Symfony 3.x 之前修复表单 DeprecatedWarning(s)?
【发布时间】:2018-04-05 14:23:08
【问题描述】:

我有一个关于从 symfony2.8 到 symfony3.x 的更新过程的小问题。 我有很多不推荐使用的警告,我想在开始更新之前修复这些警告。

但我无法修复它,因为似乎某些(新)功能在 2.8 版中不可用。可以吗?

例如:

   Accessing type "text" by its string name is deprecated since Symfony 2.8 and will be removed in 3.0. Use the fully-qualified type class name "Symfony\Component\Form\Extension\Core\Type\TextType" instead. (3 times)  Show stack trace

这意味着,我应该自定义我的表单:

->add('birthyear', 'text', array(
            'label' => 'Year of birth',
            'attr' => array('placeholder'=>'yyyy'),
            'required' => false,
    ))

到...

->add('birthyear', Symfony\Component\Form\Extension\Core\Type\TextType:class, array(
            'label' => 'Year of birth',
            'attr' => array('placeholder'=>'yyyy'),
            'required' => false,
    ))

但是我当前的版本中不存在这个文件夹和路径。

Symfony\Component\Form\Extension\Core\Type\TextType

我应该在更新后修复它吗?或者我必须做哪种解决方法?我很困惑,因为在 Symfony 文档中写着“你应该先修复它”。

感谢您的反馈!

【问题讨论】:

  • 您当前的版本是 2.8? TextType 已经存在了很长时间。当类名完全拼写出来时,您不应该使用 ::class。还是有其他问题?没有根本原因您不能在保留 2.8 的同时消除所有弃用消息。
  • 感谢您的反馈。我用新的组件安装了文件夹,现在它可以工作了!

标签: symfony symfony-2.8


【解决方案1】:
use Symfony\Component\Form\Extension\Core\Type\TextType;

->add('birthyear', TextType::class, array(
            'label' => 'Year of birth',
            'attr' => array('placeholder'=>'yyyy'),
            'required' => false,
    ))

【讨论】:

  • 您好感谢您的回复!不,它不起作用。在我写我的问题之前我试过了。我得到了答案:无法加载类型“General\CommonBundle\Form\TextType”:类不存在。
  • @helmi 您遗漏了使用声明。但我从另一条评论中看到你得到了它的工作。
  • 嘿,谢谢,抱歉,这是复制和粘贴错误!非常感谢您的投资时间!
猜你喜欢
  • 2018-09-29
  • 2017-03-22
  • 2023-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-17
  • 1970-01-01
  • 2019-02-21
相关资源
最近更新 更多