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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:11:52+00:00 2026-05-28T04:11:52+00:00

How can I eliminate to write $object = new Application_Model_Database() in every controller? For

  • 0

How can I eliminate to write $object = new Application_Model_Database() in every controller?

For example for an article controller, I have to type $articles = new Application_Model_Articles() for every controller. Should I put it under viewer controller, action helpers, or any other way?

  • 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-05-28T04:11:53+00:00Added an answer on May 28, 2026 at 4:11 am

    Your question almost sounds like an OOP best practices question as opposed to a Zend Framework specific question. Regardless of whether or not I’m using a framework, and regardless of what framework I choose, I base when and where I create new objects on testability how many times I have to write $object = new My_Random_Object();.

    Speaking specifically to the Zend Framework: Objects I’m going to use everywhere, or almost everywhere, get created in Bootstrap.php. These objects generally include a database adapter, logger, view object, and any plugins I might use. To access these across the application, I’ll create private properties in the appropriate controllers and assign the objects to those properties in the controller’s init() method.

    class ExampleController extends Zend_Controller_Action
    {
    
        public function init()
        {
            $bootstrap = $this->getInvokeArg('bootstrap');
            $this->_db = $bootstrap->getResource('db');
            $this->_log = $bootstrap->getResource('log');
            // and so on, and so forth
        }
    
    }
    

    Ideally, models, services, daos, etc, will all be relatively tightly grouped by controller and by action. In my experience, and this is speaking generally, if I have the same model or service class showing up across all of the controllers in my application, I have an organization problem. That being said, any model that shows up in only one action gets created in that action. If it’s across actions in a controller, it gets created in the init() method and assigned to a property. If it shows up across multiple controllers, it gets created in my Bootstrap.php.

    (Ideally, everything gets created in the Bootstrap.php, so you can swap out that bootstrap for testing purposes. Sadly, I don’t always do that, and I most often use the principles I outlined above.)

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

Sidebar

Related Questions

How can I format the following line to eliminate StyleCop warnings: this.BeginInvoke(this.updateHandler,new object[]{this.tmpbuf}); Now,
how can i eliminate multiple number of return statements to one statement. example: i
How can I eliminate duplicate in an array using PHP, array looks like below
I've heard about how base classes and method overriding can be combined to eliminate
can you recommend some good ASP.NET tutorials or a good book? Should I jump
I have the following Domain Object: public class DomainClass { public int Id {
I have a Concurrency::concurrent_vector and want to push_back thread safe a new element only
Recently, I found myself having to write up some concerns I have about race
I have a Reason object: public class Reason { public virtual long Id {
I haven't checked with IE9 but I have a simple JS that utilizes document.write

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.