Zend framework2 ZF2 User\Module.php无法调用$sm->;获取(';Zend\Db\Adapter\Adapter';)
我正在学习ZF2,开始编写一个用于身份验证的简单UserAuth插件,但有以下例外: 创建“userAuth”时引发异常;没有返回任何实例 以前的例外情况: 提供的或实例化的驱动程序对象未实现Zend\Db\Adapter\driver\DriverInterface 此行出错:$sm->get('Zend\Db\Adapter\Adapter')) 下面是我的User\Module.php 类模块{Zend framework2 ZF2 User\Module.php无法调用$sm->;获取(';Zend\Db\Adapter\Adapter';),zend-framework2,Zend Framework2,我正在学习ZF2,开始编写一个用于身份验证的简单UserAuth插件,但有以下例外: 创建“userAuth”时引发异常;没有返回任何实例 以前的例外情况: 提供的或实例化的驱动程序对象未实现Zend\Db\Adapter\driver\DriverInterface 此行出错:$sm->get('Zend\Db\Adapter\Adapter')) 下面是我的User\Module.php 类模块{ public function onBootstrap(MvcEvent $e) {
public function onBootstrap(MvcEvent $e)
{
$e->getApplication()->getServiceManager()->get('translator');
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
}
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getServiceConfig()
{
return array(
'invokables' => array(
),
'factories' => array(
'User\Form\Signin' => function($sm) {
$form = new Form\Signin();
$form->setInputFilter(new Form\SigninFilter);
return $form;
},
'User\Auth\Service' => function ($sm) {
return new \Zend\Authentication\AuthenticationService(
new \Zend\Authentication\Storage\Session(),
new \Zend\Authentication\Adapter\DbTable($sm->get('Zend\Db\Adapter\Adapter'))
);
},
),
);
}
public function getControllerPluginConfig()
{
return array(
'factories' => array(
'UserAuth' => function ($sm) {
$sl = $sm->getServiceLocator();
$authService = $sl->get('User\Auth\Service');
$authAdapter = new \Zend\Authentication\Adapter\DbTable($sm->get('Zend\Db\Adapter\Adapter'));
$controllerPlugin = new Controller\Plugin\UserAuth();
$controllerPlugin->setAuthService($authService);
$controllerPlugin->setAuthAdapter($authAdapter);
return $controllerPlugin;
},
),
);
}
}
请帮助我修复它。添加:
use Zend\Db\Adapter\Adapter;
到Controller\Plugin\UserAuth.php的顶部
以及:
之后:
class UserAuth
在同一个文件中。这至少会让你走上正确的方向。你真的读过ZfcUser的文档吗?有一节是关于这个特定部分的,我在autoload/local.php中有db config,还有一个配置的factory/service?global.php返回数组('db'=>array('driver'=>'Pdo','driver_options'=>array(Pdo::MYSQL_ATTR_INIT_COMMAND=>'SET NAMES'UTF8\'')),“服务管理器”=>array('factories'=>array('Zend\Db\Adapter\Adapter'=>'Zend\Db\Adapter\Adapter\AdapterServiceFactory',),),)$authAdapter=new\Zend\Authentication\Adapter\DbTable($sm->get('Zend\Db\Adapter\Adapter'));应该是$authAdapter=new\Zend\Authentication\Adapter\DbTable($sl->get('Zend\Db\Adapter\Adapter'));
class UserAuth