PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 18, 2022

[FIXED] How to hide events that happened today and have passed ? Symfony

 October 18, 2022     symfony, time     No comments   

Issue

In my Symfony project, I have created the table "event" and datatime field in it named start. In twig, I wish to filter and display upcoming events. So events that have passed would be visible any more.

At the moment, I used {% if event.start > date() %}. It worked to hide events that happened days before today. I wanted also to hide events that already happened today but currently it doesn't work when time has passed of the today's event.

How can I hide events that time already has passed ?


Solution

Here is a better solution (I precise that an address is given to events, and address has a "bigcity" registered, this why I am using LocationRepository) :

EventController.php

    #[Route('/events', name: 'events')]
    public function events(
        Request $request, 
        EventRepository $eventRepository, 
        CategoryRepository $categoryRepository,
        BigCityRepository $bigcityRepository,
        LocationRepository $locationRepository
    ){
        $category = $categoryRepository->findOneById($request->query->get('category'));
        $bigcity = $bigcityRepository->findOneById($request->query->get('bigcity'));
        $location = $locationRepository->findAll($request->query->get('location.bigcity'));

        $events = $eventRepository->findBy(['category' => $category, 'address' => $location]);
        return $this->render("front/events.html.twig", [
            'events' => $events,
            'category' => $category,
            'bigcity' => $bigcity
        ]);
    }


Answered By - Emilie Tossan
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing