Symfony:CreateForm/为什么我的textarea没有出现? [英] Symfony : CreateForm / Why my textarea do not appear?
问题描述
我在用Symfony创建的表单中显示文本区域时遇到问题.
I have a problem to display a textarea from a form I've created with Symfony.
文本区域显示为html,但在CSS中没有 display:block
.需要清楚的是,css中没有任何内容.
The textarea appears in html but it has no display: block
in the css. It has nothing in the css, to be clear.
当我自己在CSS中添加 display:block
时,它只是被chrome/firefox剥离了.
When I add a display:block
in the css myself, it simply stripped by chrome/firefox.
仅当我从单独的类创建表单时才会发生此问题,而不是在控制器的函数中创建表单时才会发生.
The problem only happens when I create the form from a separate Class, not when I create it in controller's function.
这是我的代码:
AdController.php
AdController.php
<?php
namespace App\Controller;
use App\Entity\Ad;
use App\Form\AdType;
use App\Repository\AdRepository;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class AdController extends AbstractController
{
/**
* Create ad
*
* @Route("/ads/new", name="ads_create")
*
* @return Response
*/
public function create(){
$ad = new Ad();
$form = $this->createForm(AdType::class, $ad);
return $this->render('ad/new.html.twig', [
'form' => $form->createView()
]);
}
}
AdType.php
AdType.php
<?php
namespace App\Form;
use App\Entity\Ad;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
class AdType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title')
->add('slug')
->add('price')
->add('introduction')
->add('content', TextareaType::class, [
'attr' => array('cols' => '5', 'rows' => '5')])
->add('coverImage')
->add('rooms')
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Ad::class,
]);
}
}
还有树枝:
{% extends 'base.html.twig' %}
{% form_theme form 'bootstrap_4_layout.html.twig' %}
{% block title %}Create ad{% endblock %}
{% block body %}
<div class="container">
<h1>lorem ipsum</h1>
{{form_start(form)}}
{{ form(form) }}
{{form_end(form)}}
</div>
{% endblock %}
我尝试了很多事情,但是我仍然不知道如何解决这个问题.有人对此有想法吗?
I tried a lot of things but I still don't understand how to solve this problem. Do someone have an idea about it ?
提前谢谢!
推荐答案
我遇到了同样的问题
解决方案是要禁用AdBlock
SOLUTION was to disable AdBlock
Adblock隐藏了文本区域,因为它认为这是一个广告(您的实体名称以"ad"前缀开头)
Adblock hid the textarea beacause it thought it was an ad (your entities name begin with the "ad" prefix)
这篇关于Symfony:CreateForm/为什么我的textarea没有出现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!