0

我正在通过开始编写一个简单的 UserAuth 插件来进行身份验证来学习 ZF2,但是遇到了异常:创建“userAuth”时引发了异常;没有返回实例以前的异常:提供的或实例化的驱动程序对象没有实现 Zend\Db\Adapter\Driver\DriverInterface

这一行的错误: $sm->get('Zend\Db\Adapter\Adapter')

以下是我的 User\Module.php

类模块{

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;
            },
        ),
    );
}

}

请帮我修复它。

4

1 回答 1

0

添加:

use Zend\Db\Adapter\Adapter;

到 Controller\Plugin\UserAuth.php 的顶部

和:

extends Adapter

后:

class UserAuth

在同一个文件中。这至少会让你朝着正确的方向前进。

于 2013-05-07T22:09:31.727 回答