Symfony3"选项"占位符"不存在。"

时间:2016-12-17 16:14:34

标签: php forms symfony

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

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

以下是示例代码:

//...

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

使用这些值我在浏览器中收到此错误:

  

选项"占位符"不存在。定义的选项是:   " 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_class","禁用"," empty_data",   " error_bubbling"," error_mapping"," extra_fields_message",   " inherit_data"," invalid_message"," invalid_message_parameters",   "标签"," label_attr"," label_format","映射","方法",   " 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; 

1 个答案:

答案 0 :(得分:18)

placeholder是一个html属性。

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