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 9086831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:34:57+00:00 2026-06-16T21:34:57+00:00

How can I use dynamic entity names in a controller action, in Zend framework

  • 0

How can I use dynamic entity names in a controller action, in Zend framework 2 using Doctrine 2?

For eg.

public function indexAction()
    {
        return new ViewModel(array(
            'albums' => $this->getEntityManager()->getRepository('Album\Entity\[dynamic_entity_name]')->findAll() 
        ));
    }

Also, in first place, can I even USE multiple entities in a single controller, like my case here?

The root of doing something like this is, I basically have two modes in my application, live and test, where the users can save data in either mode (something like sandbox and live modes of a payment gateway back-end).

I need to have two different tables, one for each mode; say for e.g., payment_test and payment_live tables for the payments that user makes.

So in my controller, based on the current mode (test or live) that user is using, the data should be retrieved from / saved to the respective entities (PAYMENT_LIVE or PAYMENT_TEST).

I believe checking conditions for the current mode at all the places is a bad bad idea, hence I will just set it in some CURRENT_MODE CONSTANT once, and then use it for using the entity name dynamically, something like:

    public function indexAction()
        {
            return new ViewModel(array(
                'payments' => $this->getEntityManager()->getRepository('Payment\Entity\Payment_'.CURRENT_MODE.')->findAll() 
));
        }

which will use Payment_live entity for live mode and Payment_test entity for test mode, based on value of CURRENT_MODE = “live” or “test”.

Any thoughts how should I go about implementing this?

  • 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-16T21:34:58+00:00Added an answer on June 16, 2026 at 9:34 pm

    My first thought was: Why having two tables and not just an identifier to query the mode for. A field insire you table payments called payment_modus (could be a boolean for live true/false) or something.

    Other than that, of course you can have multiple repositories in one controller.

    $repo = 'Payment\Entity\Payment_'.$this->getCurrentMode();
    $em->getRepository($repo);
    

    Kinda difficult to answer since i don’t really understand where your problem actually lies.

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

Sidebar

Related Questions

Can I use two different back ends for an .net Entity Framework project? I
Using Entity Framework I can create concrete classes from most of the sprocs in
Can I use dynamic data type in WF 4.0? And if this is possible
I can create and use dynamic two dimensional array in Fortran (in 77 standard).
If I want to make a rule dynamic so i can use assert after
how can I create a dynamic lambda expression to pass to use in my
How can be possible to use Google analytic with blogger dynamic views? I cannot
I have been trying to use dynamic LINQ to Entity in my application for
To begin with: Using Entity Framework v4.0. ASP.NET MVC 2.0. Visual Studio 2010. I
I am using .net framework 3.5 framework & for database operations entity framework. So,

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.