Skip to content

Extends ServiceEntityRepository instead of EntityRepository #41

Description

@fclausset

In the day 6, with SF 4, we could extend ServiceEntityRepository for the repositories as per the symfony doc

It allows you to use autowiring and thus less boiler plate.

use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Persistence\ManagerRegistry;

class CategoryRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, Category::class);
    }
...
}

and then in the JobController

use App\Repository\CategoryRepository;
...

public function list(CategoryRepository $categoryRepository) : Response
{
    $categories = $categoryRepository->findWithActiveJobs();

    return $this->render('job/list.html.twig', [
            'categories' => $categories,
     ]);
}

Anyway it also works with EntityRepository.

Thanks for the great Job.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions