請注意:這是ZF測試1.我懷疑這是當前版本ZF2依賴注入 - 注入表到類
一樣,我只是試圖依賴注入我的一些課程。我以爲我有這個問題,因爲我已經用很多東西來管理它,比如將database configurations
,DB adapters
和auth adapters
注入到我的UserMapper
課程中。
我試圖做一些與我的一些其他類,並根本無法工作爲什麼它只是不像我的UserMapper
類一樣工作。現在我看到UserMapper
類正被注入到一個控制器中,該控制器在配置文件的頂部爲其設置了一個別名。
所以我猜沒有通過使用控制器首先注入...我應該如何注入我的模型?我使用的是標準ZF2 Skeleton by EvanDotPro
我的模型是:
Application\Model\
Application\Model\DbTable
我的配置目前看起來是這樣:
<?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',
),
),
),
),
);
感謝,多米尼克