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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:42:41+00:00 2026-05-27T04:42:41+00:00

Please note: This was ZF beta 1. I doubt this is the same for

  • 0

Please note: This was ZF beta 1. I doubt this is the same for current release

I was just attempting to inject dependencies into some of my classes. I thought I had this down as I was already managing it with quite a few things like injecting database configurations, DB adapters and auth adapters into my UserMapper class.

I was trying to do the same with some other classes of mine and couldn’t work out at all why it just wasn’t working like my UserMapper class was. Now I see that the UserMapper class is being injected into a controller which has an alias set for it at the top of the config file.

So I guess without having it first injected by using a controller… how am I supposed to be injecting stuff into my Models? I’m using the standard ZF2 Skeleton by EvanDotPro

My Models are in:

Application\Model\
Application\Model\DbTable

My config currently looks something like:

<?php
return array(
'bootstrap_class' => 'Application\Bootstrap',
'layout'          => 'layouts/layout.phtml',
'di'              => array(
    'instance' => array(
        'alias' => array(
            'index'             => 'Application\Controller\IndexController',
            'view'              => 'Zend\View\PhpRenderer'
        ),

        'Zend\View\HelperLoader' => array(
            'parameters' => array(
                'map' => array(
                    'url' => 'Application\View\Helper\Url',
                ),
            ),
        ),

        'Zend\View\HelperBroker' => array(
            'parameters' => array(
                'loader' => 'Zend\View\HelperLoader',
            ),
        ),

        'Application\Controller\IndexController' => array(
            'parameters' => array(
                'userMapper' => 'Application\Model\UserMapper',
                'flashMessenger' => 'Zend\Mvc\Controller\Plugin\FlashMessenger'
            )
        ),

        'Application\Model\UserMapper' => array(
            'parameters' => array(
                'db' => 'Zend\Db\Adapter\PdoMysql',
                'authAdapter' => 'Zend\Authentication\Adapter\DbTable',
                'userTable' => 'Application\Model\DbTable\UserTable'
            )
        ),

        'Application\Model\DbTable\UserTable' => array(
            'parameters' => array(
                'config' => 'Zend\Db\Adapter\PdoMysql',
            )
        ),

            // Auth adapter

        'Zend\Authentication\Adapter\DbTable' => array(
            'parameters' => array(
                'zendDb' => 'Zend\Db\Adapter\PdoMysql',
                'tableName' => 'users',
                'identityColumn' => 'username',
                'credentialColumn' => 'password',
                'credentialTreatment' => 'MD5(CONCAT(?,"OSalTyr$"))'
            )
        ),

        // DB Adapter

        'Zend\Db\Adapter\PdoMysql' => array(
            'parameters' => array(
                'config' => array(
                    'host' => 'localhost',
                    'username' => 'root',
                    'password' => '',
                    'dbname' => 'blahblah',
                ),
            ),
        ),

        // View

        'Zend\View\PhpRenderer' => array(
            'parameters' => array(
                'resolver' => 'Zend\View\TemplatePathStack',
                'options'  => array(
                    'script_paths' => array(
                        'application' => __DIR__ . '/../views',
                    ),
                ),
                'broker' => 'Zend\View\HelperBroker',
            ),
        ),

    ),
),

'routes' => array(
    'default' => array(
        'type'    => 'Zend\Mvc\Router\Http\Regex',
        'options' => array(
            'regex'    => '/(?P<controller>[^/]+)(/(?P<action>[^/]+)?)?',
            'spec'     => '/%controller%/%action%',
            'defaults' => array(
                'controller' => 'error',
                'action'     => 'index',
            ),
        ),
    ),
    'home' => array(
        'type' => 'Zend\Mvc\Router\Http\Literal',
        'options' => array(
            'route'    => '/',
            'defaults' => array(
                'controller' => 'index',
                'action'     => 'index',
            ),
        ),
    ),
),
);

Thanks, Dominic

  • 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-27T04:42:42+00:00Added an answer on May 27, 2026 at 4:42 am

    Ahah… I found out why this wasn’t working.

    Although the above config is correct and I’m defining what I want injecting into what… I wasn’t actually using the injected instance of the object in question.

    I thought when using ‘new thingy();’ that DI would magically pick up that it has dependencies and apply them when needed but this is not the case…

    What I infact needed to do… was inject the thingy class into my UserMapper class like a chain and then use the injected instance instead of creating it a new instance of it without stuff injected into it.

    Like:

    RegisterController requires UserMapper so inject it in and use that instance
    UserMapper requires Thingy so inject it in and use that instance

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

Sidebar

Related Questions

Please note this is just an example: <img src=img/normal-font.png onclick=javascript:document.body.style.fontSize = '13px'; /> &nbsp;
I was just reading this article :- http://css-tricks.com/perfect-full-page-background-image/ Please note this css :- #bg
Please note: This is a question about the Eclipse plugin Subversive , and not
Please note this is not a question about online/hosted SVN services. I am working
[Please note that this is a different question from the already answered How to
Please note that this is not homework and i did search before starting this
Please note that this question is from 2008 and now is of only historic
Please note that I did ask this on Super User and received absolutely no
Please note: In each step I describe below I'm logged in as the same
Please note this is a question with regard to Backbone.js. This is not a

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.