createFormBuilder($use-6ren">
gpt4 book ai didi

php - Symfony3 "The option "占位符“不存在”。

转载 作者:可可西里 更新时间:2023-10-31 23:04:55 25 4
gpt4 key购买 nike

我想创建一个用户设置面板。

在表单中,我希望有一个占位符,其中包含用户为其参数设置的当前值。

这是一个示例代码:

//...

$form = $this->createFormBuilder($user)
->add('Username', TextType::class, array(
'label' => "Change UserName",
'placeholder' => $userData[0]->getUsername()
))
//...

使用这样的值我在浏览器中得到这个错误:

The option "placeholder" does not exist. Defined options are: "action", "allow_extra_fields", "attr", "auto_initialize", "block_name", "by_reference", "compound", "constraints", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_token_id", "csrf_token_manager", "data", "data_class", "disabled", "empty_data", "error_bubbling", "error_mapping", "extra_fields_message", "inherit_data", "invalid_message", "invalid_message_parameters", "label", "label_attr", "label_format", "mapped", "method", "post_max_size_message", "property_path", "required", "translation_domain", "trim", "upload_max_size_message", "validation_groups".

问题仅出在参数本身,因为 'data' => $userData[0]->getUsername() 工作并显示正确的信息。

我的页面使用参数如下:

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use AppBundle\Entity\Task;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use AppBundle\Entity\Post;
use AppBundle\Entity\User;

最佳答案

placeholder 是一个 HTML 属性,可以使用 TextType attr 添加选项。

$form = $this->createFormBuilder($user)
->add('Username', TextType::class, array(
'label' => "Change UserName",
'attr' => array(
'placeholder' => $userData[0]->getUsername(),
)
));

关于php - Symfony3 "The option "占位符“不存在”。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41200549/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com