Bonjour,
Je rencontre un petit problème avec mon code.
J'aimerai affiché mon formulaire en entier, mais voilà un de mes champ ne veux pas s'afficher
(le champ cont qui est un textArea).
Voici le code de mon controller :
<?php
namespace App\Controller;
use App\Entity\Ad;
use App\Form\AdType;
use App\Repository\AdRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class AdController extends AbstractController
{
/**
* @Route("/ads", name="ads_index")
* @param AdRepository $repo
* @return Response
*/
public function index(AdRepository $repo): Response
{
$ads = $repo->findAll();
return $this->render(
'ad/index.html.twig',
[
'ads' => $ads,
]
);
}
/**
* @Route("/ads/new", name="new_ad")
*/
public function create(): Response
{
$ads = new Ad();
$form = $this->createForm(AdType::class, $ads);
return $this->render('ad/create.html.twig', [
'form' => $form->createView(),
]
);
}
/**
* @Route ("/ads/{slug}", name="ad_show")
* @param Ad $ad
* @return Response
*/
public function show(Ad $ad) : Response
{
return $this->render(
'ad/show.html.twig',
[
'ad' => $ad,
]
);
}
}
Celui de mon twig :
{% extends 'base.html.twig' %}
{% block body %}
<div class="container">
{{ form(form) }}
</div>
{% endblock %}
Celui de mon modèle :
<?php
namespace App\Entity;
use App\Repository\AdRepository;
use Cocur\Slugify\Slugify;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=AdRepository::class)
* @ORM\HasLifecycleCallbacks()
*/
class Ad
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\Column(type="string", length=255)
*/
private $slug;
/**
* @ORM\Column(type="float")
*/
private $price;
/**
* @ORM\Column(type="text")
*/
private $introduction;
private $cont;
/**
* @ORM\Column(type="string", length=255)
*/
private $coverImage;
/**
* @ORM\Column(type="integer")
*/
private $rooms;
/**
* @ORM\OneToMany(targetEntity=Image::class, mappedBy="ad")
*/
private $images;
public function __construct()
{
$this->images = new ArrayCollection();
}
/**
* Permet d'initaliser le slug !
* @ORM\PrePersist
* @ORM\PreUpdate
* @return Void
*/
public function initializeSlug()
{
if (empty($this->slug))
{
$slugify = new Slugify();
$this->slug = $slugify->slugify($this->title);
}
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getPrice(): ?float
{
return $this->price;
}
public function setPrice(float $price): self
{
$this->price = $price;
return $this;
}
public function getIntroduction(): ?string
{
return $this->introduction;
}
public function setIntroduction(string $introduction): self
{
$this->introduction = $introduction;
return $this;
}
public function getCont(): ?string
{
return $this->cont;
}
public function setCont(string $cont): self
{
$this->cont = $cont;
return $this;
}
public function getCoverImage(): ?string
{
return $this->coverImage;
}
public function setCoverImage(string $coverImage): self
{
$this->coverImage = $coverImage;
return $this;
}
public function getRooms(): ?int
{
return $this->rooms;
}
public function setRooms(int $rooms): self
{
$this->rooms = $rooms;
return $this;
}
/**
* @return Collection|Image[]
*/
public function getImages(): Collection
{
return $this->images;
}
public function addImage(Image $image): self
{
if (!$this->images->contains($image)) {
$this->images[] = $image;
$image->setAd($this);
}
return $this;
}
public function removeImage(Image $image): self
{
if ($this->images->removeElement($image)) {
// set the owning side to null (unless already changed)
if ($image->getAd() === $this) {
$image->setAd(null);
}
}
return $this;
}
}
Et enfin celui de mon formulaire :
<?php
namespace App\Form;
use App\Entity\Ad;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class AdType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options) : void
{
$builder
->add('title')
->add('slug', TextType::class)
->add('price')
->add('introduction')
->add('cont', TextType::class)
->add('coverImage')
->add('rooms')
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Ad::class,
]);
}
}
Note : Dans chrome mon champ s'affiche mais pas dans firefox !
Je voudrai que tous mon formulaire ainsi que mon champ cont s'affiche
Merci de vos éventuels réponses !
Tu copie ici beaucoup trop de code. Si c'est un bug visuel alors regarde plutôt avec l'inspecteur de ton navigateur. Le code côté serveur ne nous sert pas.