NoneFormtype , контроллер, репозиторий в Symfony с объединением в 3 объекта
Я пытаюсь получить все поля из всех моих таблиц с помощью кнопки выбора выбора в форме поиска контроллера, который получает запрос, в котором я запрашиваю отобразить весь рабочий пост (postte) и рабочий час (horaire) для Выбор chefTeam соответствует кнопке. Для того, чтобы отобразить в таблице 3 сущности в ветке согласно руководителю группы.
Это была неделя, когда я нахожусь на этом, и это все еще не работает
LE CONTROLEUR
Я думаю, что есть много проблем, и думаю, что это контроллер, потому что я не нахожу массив $postes. Я не делаю этого.
PHP
/**
* @Route("/", name="filter_index", methods={"GET","POST"})
*/
public function index(Request $resquest, FilterRepository $filterRepository): Response
{
{// creation du formulaire
$filterType = $this->createForm(FilterType::class);
// Il n'est pas mappé
$filterType->handleRequest($resquest);
if ($filterType->isSubmitted() && $filterType->isValid()) {
// Requête recupére poste et horaire par chefEquipe
$postes = $filterRepository->filter( $filterType->get('chefEquipe')->getData());
// On redirige vers la vue
return $this->render('filter/index.html.twig', ['postes' => $postes, 'filterType' => $filterType->createView()]);
}
return $this->render('filter/index.html.twig', [ 'filterType' => $filterType->createView(),
]);
}
}
LE FORMTYPE
php
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder ->
add('chefEquipe', EntityType::class, [
'class' => ChefEquipe::class,
//Requete avec le query builder recupére chefEquipe affichage avec un bouton
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('c')
->orderBy('c.chefEquipe', 'ASC');
},
'choice_label' => 'chefEquipe',
'label' => 'Chef Equipe', 'placeholder' => 'Tous', 'required' => false
]);
$builder->add('Valider', SubmitType::class, ['attr' => ['class' => 'hollow button secondary']]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'mapped' => false,
]);
}
LE Хранилище
php
public function __construct(RegistryInterface $registry)
{
parent::__construct($registry, Poste::class);
}
public function filter(?ChefEquipe $chefEquipe)
{
$conn = $this->getEntityManager()
->getConnection();
$sql = 'SELECT * FROM chef_equipe INNER JOIN poste as po ON chef_equipe.chef_equipe = po.chef_equipe INNER JOIN horaire as ho ON chef_equipe.chef_equipe = ho.chef_equipe WHERE chef_equipe.chef_equipe="BRICARD GERALD" ';
$stmt = $conn->prepare($sql);
$stmt->execute(array('chefEquipe' => $chefEquipe->getId()));
var_dump($stmt->fetchAll());die;
}
Может быть, есть лучше для этого запроса?!
Мой ШАБЛОН
php
{% extends 'base.html.twig' %}
{% block title %}Poste index{% endblock %}
{% block body %}
{% include 'filter/search.html.twig' %}
<h1>Poste index</h1>
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Lundi</th>
<th>Mardi</th>
<th>Mercredi</th>
<th>Jeudi</th>
<th>Vendredi</th>
<th>Samedi</th>
<th>Dimanche</th>
<th>ChefEquipe</th>
<th>Equipe</th>
<th>actions</th>
</tr>
</thead>
<tbody>
{% for poste in postes %}
<tr>
<td>{{ poste.id }}</td>
<td>{{ horaire.nomPrenom }}</td>
<td>{{ poste.lundi }}</td>
<td>{{ horaire.lundi }}</td>
<td>{{ poste.mardi }}</td>
<td>{{ horaire.mardi }}</td>
<td>{{ poste.mercredi }}</td>
<td>{{ horaire.mercredi }}</td>
<td>{{ poste.jeudi }}</td>
<td>{{ horaire.jeudi }}</td>
<td>{{ poste.vendredi }}</td>
<td>{{ horaire.vendredi }}</td>
<td>{{ poste.samedi }}</td>
<td>{{ horaire.samedi }}</td>
<td>{{ poste.dimanche }}</td>
<td>{{ horaire.dimanche }}</td>
<td>{{ poste.chefEquipe }}</td>
<td>{{ horaire.chefEquipe }}</td>
<td>{{ chefequipe.chefEquipe }}</td>
<td>{{ poste.equipe }}</td>
<td>
<a href="{{ path('poste_show', {'id': poste.id}) }}">show</a>
<a href="{{ path('poste_edit', {'id': poste.id}) }}">edit</a>
</td>
</tr>
{% else %}
<tr>
<td colspan="11">no records found</td>
</tr>
{% endfor %}
</tbody>
</table>
<a href="{{ path('poste_new') }}">Create new</a>
{% endblock %}
`` `
TEMPLATE FORM WITH CHOICE`` `php
{% extends 'base.html.twig' %}
{% block title %}Search{% endblock %}
{% block body %}
{{ form_start(filterType) }}
{{ form_widget(filterType) }}
{{ form_end(filterType) }}
{% endblock %}
Моя сущность
PHP
/**
* Poste
*
* @ORM\Table(name="poste", uniqueConstraints={@ORM\UniqueConstraint(name="nom_prenom", columns={"nom_prenom"})})
* @ORM\Entity
*/
class Poste
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string|null
*
* @ORM\Column(name="lundi", type="string", length=255, nullable=true)
*/
private $lundi;
/**
* @var string|null
*
* @ORM\Column(name="mardi", type="string", length=255, nullable=true)
*/
private $mardi;
/**
* @var string|null
*
* @ORM\Column(name="mercredi", type="string", length=255, nullable=true)
*/
private $mercredi;
/**
* @var string|null
*
* @ORM\Column(name="jeudi", type="string", length=255, nullable=true)
*/
private $jeudi;
/**
* @var string|null
*
* @ORM\Column(name="vendredi", type="string", length=255, nullable=true)
*/
private $vendredi;
/**
* @var string|null
*
* @ORM\Column(name="samedi", type="string", length=255, nullable=true)
*/
private $samedi;
/**
* @var string|null
*
* @ORM\Column(name="dimanche", type="string", length=255, nullable=true)
*/
private $dimanche;
/**
* @var string
*
* @ORM\Column(name="chef_equipe", type="string", length=255, nullable=false)
*/
private $chefEquipe;
/**
* @var string
*
* @ORM\Column(name="equipe", type="string", length=1000, nullable=false)
*/
private $equipe;
/**
* @var Horaire
*
* @ORM\ManyToMany(targetEntity="Horaire")
* @ORM\JoinColumn(name="nom_prenom", referencedColumnName="nom_prenom")
*
*/
private $nomPrenom;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $nom_prenom;
public function getId(): ?int
{
return $this->id;
}
public function getLundi(): ?string
{
return $this->lundi;
}
public function setLundi(?string $lundi): self
{
$this->lundi = $lundi;
return $this;
}
public function getMardi(): ?string
{
return $this->mardi;
}
public function setMardi(?string $mardi): self
{
$this->mardi = $mardi;
return $this;
}
public function getMercredi(): ?string
{
return $this->mercredi;
}
public function setMercredi(?string $mercredi): self
{
$this->mercredi = $mercredi;
return $this;
}
public function getJeudi(): ?string
{
return $this->jeudi;
}
public function setJeudi(?string $jeudi): self
{
$this->jeudi = $jeudi;
return $this;
}
public function getVendredi(): ?string
{
return $this->vendredi;
}
public function setVendredi(?string $vendredi): self
{
$this->vendredi = $vendredi;
return $this;
}
public function getSamedi(): ?string
{
return $this->samedi;
}
public function setSamedi(?string $samedi): self
{
$this->samedi = $samedi;
return $this;
}
public function getDimanche(): ?string
{
return $this->dimanche;
}
public function setDimanche(?string $dimanche): self
{
$this->dimanche = $dimanche;
return $this;
}
public function getChefEquipe(): ?string
{
return $this->chefEquipe;
}
public function setChefEquipe(string $chefEquipe): self
{
$this->chefEquipe = $chefEquipe;
return $this;
}
public function getEquipe(): ?string
{
return $this->equipe;
}
public function setEquipe(string $equipe): self
{
$this->equipe = $equipe;
return $this;
}
public function getNomPrenom():? Horaire
{
return $this->nomPrenom;
}
public function setNomPrenom(?Horaire $nomPrenom): self
{
$this->nomPrenom = $nomPrenom;
return $this;
}
public function __toString()
{
return $this->chefEquipe = $this->getChefEquipe() ;
}
PHP
* @ORM\Entity(repositoryClass="App\Repository\ChefEquipeRepository")
*/
class ChefEquipe
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $chefEquipe;
public function getId(): ?int
{
return $this->id;
}
public function getChefEquipe(): ?string
{
return $this->chefEquipe;
}
public function setChefEquipe(?string $chefEquipe): self
{
$this->chefEquipe = $chefEquipe;
return $this;
}
}