请注意:这是 ZF beta 1。我怀疑这与当前版本相同
我只是试图将依赖项注入我的一些类。我以为我已经解决了这个问题,因为我已经用很多东西来管理它,比如注入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',
),
),
),
),
);
谢谢,多米尼克