Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extends ServiceEntityRepository instead of EntityRepository #41

Open
fclausset opened this issue Nov 1, 2019 · 0 comments
Open

Extends ServiceEntityRepository instead of EntityRepository #41

fclausset opened this issue Nov 1, 2019 · 0 comments

Comments

@fclausset
Copy link

fclausset commented Nov 1, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant