Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8740391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:07:24+00:00 2026-06-13T11:07:24+00:00

Had a question about what best practice might be for the implementation of convenience

  • 0

Had a question about what best practice might be for the implementation of “convenience” queries. In reference to this article:

http://www.jasongrimes.org/2012/01/using-doctrine-2-in-zend-framework-2/#toc-install-doctrine-modules

It’s clear that the entity manager is available in the IndexController – he does a findAll to list the entire contents of the database. What if, however, we added a “band” column to the database, mapped it out, and wanted to query all albums by the Beatles? What if the Beatles albums were used rather often throughout the codebase (weak example, but you get it).

The EM only seems to be available in Controllers, and Classes don’t really seem to be aware of the service locator.

  • Would you simply break out DQL right in the controller, and repeat the DQL in every controller that needs it? (not very DRY)
  • Do we instead finagle some access to the EM from the Entity, or Model?

Doesn’t seem as cut-and-dry as straight Zend_Db usage where you can fire queries anywhere you like, cheating to get things done.

Thanks for helping me cross over into a “real” ORM from the Table Gateway world.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:07:25+00:00Added an answer on June 13, 2026 at 11:07 am

    Erm, Doctrine 2 is able to handle Relationships (e.g.: Bands to Albums and vice-versa)

    The EntityManager can be made available in every single class you wish, as long as you define the class as a service. I.e. inside your Module.php you can define a factory like this:

    // Implement \Zend\ModuleManager\Feature\ServiceProviderInterface
    public function getServiceConfig() {
        return array(
            //default stuff
            'factories' array(
                'my-album-service' = function($sm) {
                    $service = new \My\Service\Album();
                    $service->setEntityManager($sm->get('doctrine.entitymanager.orm_default'));
                    return $service;
                }
            )
        )
    );
    

    You can then call this class from every Class that is aware of the ServiceManager like $this->getServiceLocator()->get('my-album-service')

    This class would then automatically be injected with the Doctrine EntityManager.

    To be clear: All queries you’d do SHOULD be located inside your Services. You’d have your Entities, which are basically the DB_Mapper from Doctrine 2, then you have your Services, which run actions like add(), edit(), findAll(), findCustomQuery(), etc…

    You would then populate your Services with Data from the Controllers, the Service would give data back to the controller and the controller would pass said data to the view. Does that make sense to u and answer your question?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is more a question about what's the best practice in implementing this. I
I had a question about the best way to handle this type of data.
I had this working at some point, as I had a question about this
This is a pure best practice question. I am pretty new to Node and
Colleagues, Preamble. My question is more about best practices. I know one workaround. This
I had a question about indices on a table and I put it up
I had a question about Java Class Path variables. If I have multiple jars
I just had a question about aligning two expand-collapse boxes and got an answer
I am new to vimdiff and had a question about outputting the similarities of
I really like Play 2.0's form mapping system, but I had a question about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.