Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- It’s been a week I’m on this and It still doesn’t work ><
- LE CONTROLEUR
- I think there are many problemes and think is controller because don't find $postes array . I don't no do this .
- `` `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 REPOSITORY
- `` `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;
- }
- `` `
- Maybe there are better for this request ?!
- My TEMPLATE
- `` `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 %}
- `` `
- My ENTITY
- `` `php
- /**
- * Poste
- *
- * @ORMTable(name="poste", uniqueConstraints={@ORMUniqueConstraint(name="nom_prenom", columns={"nom_prenom"})})
- * @ORMEntity
- */
- class Poste
- {
- /**
- * @var int
- *
- * @ORMColumn(name="id", type="integer", nullable=false)
- * @ORMId
- * @ORMGeneratedValue(strategy="IDENTITY")
- */
- private $id;
- /**
- * @var string|null
- *
- * @ORMColumn(name="lundi", type="string", length=255, nullable=true)
- */
- private $lundi;
- /**
- * @var string|null
- *
- * @ORMColumn(name="mardi", type="string", length=255, nullable=true)
- */
- private $mardi;
- /**
- * @var string|null
- *
- * @ORMColumn(name="mercredi", type="string", length=255, nullable=true)
- */
- private $mercredi;
- /**
- * @var string|null
- *
- * @ORMColumn(name="jeudi", type="string", length=255, nullable=true)
- */
- private $jeudi;
- /**
- * @var string|null
- *
- * @ORMColumn(name="vendredi", type="string", length=255, nullable=true)
- */
- private $vendredi;
- /**
- * @var string|null
- *
- * @ORMColumn(name="samedi", type="string", length=255, nullable=true)
- */
- private $samedi;
- /**
- * @var string|null
- *
- * @ORMColumn(name="dimanche", type="string", length=255, nullable=true)
- */
- private $dimanche;
- /**
- * @var string
- *
- * @ORMColumn(name="chef_equipe", type="string", length=255, nullable=false)
- */
- private $chefEquipe;
- /**
- * @var string
- *
- * @ORMColumn(name="equipe", type="string", length=1000, nullable=false)
- */
- private $equipe;
- /**
- * @var Horaire
- *
- * @ORMManyToMany(targetEntity="Horaire")
- * @ORMJoinColumn(name="nom_prenom", referencedColumnName="nom_prenom")
- *
- */
- private $nomPrenom;
- /**
- * @ORMColumn(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 **
- * @ORMEntity(repositoryClass="AppRepositoryChefEquipeRepository")
- */
- class ChefEquipe
- {
- /**
- * @ORMId()
- * @ORMGeneratedValue()
- * @ORMColumn(type="integer")
- */
- private $id;
- /**
- * @ORMColumn(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;
- }
- }
- `` `
- PLEASE HELPE ME !
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement