Note that there are some explanatory texts on larger screens.

plurals
  1. POZF2 - ServiceManager and 'aware' interfaces
    primarykey
    data
    text
    <p>First ZF2 application, getting there, but I think still missing a think or two when it comes to dependency injection and the ServiceManager.</p> <p>I have a particular problem at the moment with a new database gateway class I'm writing. I won't to inject a database adapter, so I've implemented AdapterAwareInterface. But the setDbAdapter method is never called in my class. I'm wondering if someone would be so kind as to look at my code and suggest what might be going wrong (or what I'm missing!).</p> <p>So, here is the class in which I implement AdapterAwareInterface.</p> <pre><code>&lt;?php namespace Foo\Database; use Zend\Db\Adapter\Adapter; use Zend\Db\Adapter\AdapterAwareInterface; use Zend\Log\LoggerAwareInterface; use Zend\Log\LoggerInterface; class Gateway implements AdapterAwareInterface, LoggerAwareInterface { protected $logger = NULL; protected $db = NULL; public function setDbAdapter(Adapter $adapter) { $this-&gt;db = $adapter; } public function setLogger(LoggerInterface $logger) { $this-&gt;logger = $logger; } </code></pre> <p>This is an extract from my module file showing how I configure my service manager:</p> <pre><code> public function getServiceConfig() { return array( 'factories' =&gt; array( .... ), 'invokables' =&gt; array( 'FooDatabaseGateway' =&gt; 'Foo\Database\Gateway', ), 'abstract_factories' =&gt; array( 'AbstractFeedParserFactory' =&gt; 'Bookmakers\Odds\Feeds\AbstractFeedParserFactory', ), ); } </code></pre> <p>This is how I'm testing:</p> <pre><code>gateway = $this-&gt;getServiceLocator()-&gt;get('FooDatabaseGateway'); </code></pre> <p>And this is part of my global config:</p> <pre><code>return array( 'db' =&gt; array( 'driver' =&gt; 'Pdo', 'dsn' =&gt; 'mysql:dbname=kickoff_manager;host=localhost', 'username' =&gt; '****', 'password' =&gt; '****', 'driver_options' =&gt; array( PDO::MYSQL_ATTR_INIT_COMMAND =&gt; 'SET NAMES \'UTF8\'' ), ), 'service_manager' =&gt; array( 'factories' =&gt; array( 'Zend\Db\Adapter\Adapter' =&gt; 'Zend\Db\Adapter\AdapterServiceFactory', ), ), ); </code></pre> <p>Many thanks for any help you can provide.</p> <p>:wq</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload