2017-01-10 60 views
1

我正在使用zf2和zfcuser模塊與教義的項目。我創建了一個自定義用戶模塊,它擴展了zfcuser,也是用戶表的一個自定義實體,並對集成進行了所有必要的更改。但我的問題是,試圖對自己進行身份驗證時,我得到這個錯誤:zfcuser + doctrine自定義用戶實體

An alias "Zend\Db\Adapter\Adapter" was requested but no service could be found. 

這種情況zfcuser_user_mapper試圖更改適配器時。

注:我不是很清楚爲什麼我需要使用Zend \ Db \ Adapter \ Adapter,因爲我正在使用教義。

這是自定義用戶模塊的module.php中的代碼。

public function getServiceConfig() { 
    return [ 
     'aliases' => array(
      'zfcuser_zend_db_adapter' => 'Zend\Db\Adapter\Adapter', 
     ), 
     'factories' => [ 
      'usuario_login_form' => 'Usuario\Factory\Form\Login', 
      'usuario_registro_form' => 'Usuario\Factory\Form\Register', 
      'usuario_user_service' => 'Usuario\Factory\Service\UserFactory', 
      //'usuario_user_mapper' => 'Usuario\Factory\Mapper\User', 
      'usuario_auth_service' => 'Usuario\Factory\AuthenticationService', 
      'Usuario\Authentication\Adapter\Db' => 'Usuario\Factory\Authentication\Adapter\DbFactory', 
      'Usuario\Authentication\Storage\Db' => 'Usuario\Factory\Authentication\Storage\DbFactory', 
      //'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\Adapter', 
      'usuario_user_mapper' => function ($sm) { 
       $mapper = new Mapper\User(); 
       $mapper->setDbAdapter($sm->get('zfcuser_zend_db_adapter')); 
       $mapper->setEntityPrototype(new ORM\Entity\Usuarios()); 
       $mapper->setHydrator(new \ZfcUser\Mapper\UserHydrator()); 
       return $mapper; 
      }, 
     ] 
    ]; 
} 

這是我global.php文件

return array(
'doctrine' => array(
    'connection' => array(
     'orm_default' => array(
      'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver', 
      'params' => array(
       'host' => 'localhost', 
       'port' => '3306', 
       'user' => 'root', 
       'password' => 'toor', 
       'dbname' => 'deporte', 
      ) 
     ) 
    ) 
), 

);

這是我module.config.php文件:

'controllers' => array(
), 
'doctrine' => array(
    'driver' => array(
     // overriding zfc-user-doctrine-orm's config 
     'usuario_entity' => array(
      'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver', 
      'paths' => __DIR__ . '/../src/Usuario/ORM/Entity', 
     ), 
     'orm_default' => array(
      'drivers' => array(
       'Usuario\ORM\Entity' => 'usuario_entity', 
      ), 
     ), 
    ), 
), 
'zfcuser' => array(
    'auth_adapters' => array(100 => 'Usuario\Authentication\Adapter\Db'), 
    // telling ZfcUser to use our own class 
    'user_entity_class' => 'Usuario\ORM\Entity\Usuarios', 
    // telling ZfcUserDoctrineORM to skip the entities it defines 
    'enable_default_entities' => false, 
), 

感謝您對我的幫助,我已經被這個錯誤了好幾天。非常感謝你,請原諒我的英語。

+0

你安裝zfcuser-ORM-學說?而且,您是否嘗試刪除別名,「zfcuser_zend_db_adapter」=>'Zend \ Db \ Adapter \ Adapter','? –

回答

1

如果你想改變實體和想要使用,然後使用以下步驟: 如果這是擺在配置/自動加載文件夾(如果沒有,那麼你可以在從zfcuser模塊複製zfcuser.global.php文件。

在爲「user_entity_class」鍵這一全球性的文件搜索和定義自己的實體class.By默認使用

'user_entity_class' => 'ZfcUser\Entity\User', 

像我使用它的僱員實體

'user_entity_class' => 'Employee\Entity\Employee', 

在這個實體中你需要實現UserInterface。

use ZfcUser\Entity\UserInterface; 
/** 
* Employee 
* 
* @ORM\Table(name="employee") 
* @ORM\Entity(repositoryClass="Employee\Repository\EmployeeRepository") 
*/ 
class Employee implements UserInterface { 

} 

如果你想覆蓋數據庫適配器,那麼你需要做以下步驟:

'service_manager' => array(
     'invokables' => array(
      'ZfcUser\Authentication\Adapter\Db' => 'Employee\Authentication\Adapter\Db', 
     ), 
    ), 

在這個文件中,你需要擴展和工具。

namespace Employee\Authentication\Adapter; 

use InvalidArgumentException; 
use Zend\Authentication\Result as AuthenticationResult; 
use Zend\Crypt\Password\Bcrypt; 
use Zend\ServiceManager\ServiceManager; 
use Zend\ServiceManager\ServiceManagerAwareInterface; 
use Zend\Session\Container as SessionContainer; 
use ZfcUser\Authentication\Adapter\AdapterChainEvent as AuthenticationEvent; 
use ZfcUser\Entity\UserInterface as UserEntity; 
use ZfcUser\Mapper\HydratorInterface as Hydrator; 
use ZfcUser\Mapper\UserInterface as UserMapper; 
use ZfcUser\Authentication\Adapter\AbstractAdapter; 
use ZfcUser\Options\AuthenticationOptionsInterface as AuthenticationOptions; 

class Db extends AbstractAdapter implements ServiceManagerAwareInterface 
{ 

} 

欲瞭解更多信息,你可以按照zfcuser維基這裏: https://github.com/ZF-Commons/ZfcUser/wiki