Skip to content

Extends ServiceEntityRepository instead of EntityRepository #41

@fclausset

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.

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