简体   繁体   English

Symfony3“选项”占位符“不存在。”

[英]Symfony3 “The option ”placeholder“ does not exist.”

I want to create a user settings panel.我想创建一个用户设置面板。

In the form I would like to have a placeholder with the current value the user has for his param.在表单中,我想要一个占位符,其中包含用户对其参数的当前值。

Here is a sample code:这是一个示例代码:

//...

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

Using such values I get this error in the browser:使用这些值,我在浏览器中收到此错误:

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".定义的选项有:“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”。

The problem is only with the parameter itself because 'data' => $userData[0]->getUsername() works and displays the correct information.问题仅在于参数本身,因为'data' => $userData[0]->getUsername()工作并显示正确的信息。

Here are the use parameters of my page:以下是我的页面的使用参数:

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 is an HTML attribute and can be added using the TextType attr option. placeholder是一个 HTML 属性,可以使用 TextType attr选项添加。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM