I initially talked about this a couple of months ago regarding ZF2 injecting into tables with DI during Beta 1, and thought it was not possible. Now ZF2 was released as version 2.0.0, and the default ServiceManager is instead of DI. I think I have the same question as me, refactoring.
I have 84 tables that need a DbAdapter that inserts into them, and I'm sure there should be a better way, since I copy myself a lot.
public function getServiceConfig() { return array( 'factories' => array( 'accountTable' => function ($sm) { $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); $table = new Model\DbTable\AccountTable($dbAdapter); return $table; }, 'userTable' => function ($sm) { $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); $table = new Model\DbTable\UserTable($dbAdapter); return $table; },
With EventsManager and ServiceManager, I have no idea where I am in getting application instances / resources.
Thanks Dom
source share