-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Make Doctrine repository as service and autowire/use it anywhere #701
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
Conversation
@@ -54,10 +55,9 @@ class BlogController extends AbstractController | |||
* @Route("/", name="admin_post_index") | |||
* @Method("GET") | |||
*/ | |||
public function index(): Response | |||
public function index(PostRepository $postRepository): Response |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe unrelated to this PR, but in other projects I see this practice: PostRepository $postRepository
-> PostRepository $posts
. Instead of $xxxRepository
, they use the plural of $xxx
as the variable name. E.g. UserRepository $users
, ProductRepository $products
, etc. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I like that and feels better! so done.
|
||
// Every template name also has two extensions that specify the format and | ||
// engine for that template. | ||
// See https://symfony.com/doc/current/templating.html#template-suffix | ||
return $this->render('blog/index.'.$_format.'.twig', ['posts' => $posts]); | ||
return $this->render('blog/index.'.$_format.'.twig', ['posts' => $latestPosts]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about just ... ['posts' => $posts->findLatest($page)]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure ... the line would be a bit long.
Updated commands too. Ready for me! :) |
doctrine-bundle 1.8.0 is out! We have repositories as services as a native built-in feature! 🎉 🎉 |
Merged! I looooove this. @yceruto thanks for working on this! |
…anywhere (yceruto) This PR was merged into the master branch. Discussion ---------- Make Doctrine repository as service and autowire/use it anywhere Living in the edge of the [new awesome features like this](doctrine/DoctrineBundle#727), I'm proposing before doctrine-bundle 1.8 release, show/test this great feature that simplify our lives and to see how it works! and because soon, best practices should adopt this approach by default. (In fact [maker-bundle will do it](https://github.com/symfony/maker-bundle/blob/master/src/Resources/skeleton/doctrine/Repository.php.txt) <3) What do you think? Commits ------- ceac1df Make repository as service and autowire/use it anywhere
Living in the edge of the new awesome features like this, I'm proposing before doctrine-bundle 1.8 release, show/test this great feature that simplify our lives and to see how it works! and because soon, best practices should adopt this approach by default. (In fact maker-bundle will do it <3)
What do you think?