2015-04-17 69 views
1

登錄後,我是新來ZF2,我跟着一個認證教程,我發現這裏:https://samsonasik.wordpress.com/2013/05/29/zend-framework-2-working-with-authenticationservice-and-db-session-save-handler/顯示的用戶名在ZF2

登錄後,我跟着他就如何指令(在評論區)使用$this->identity()

//config/module.config.php .... 
'service_manager' => array(
    'factories' => array(
     'AuthStorage' => 'SanAuthWithDbSaveHandler\Factory\Storage\AuthStorageFactory', 
     'Zend\Authentication\AuthenticationService' => 'SanAuthWithDbSaveHandler\Factory\Storage\AuthenticationServiceFactory', 
    ), 
), 

但它生成此錯誤:

"Uncaught exception 'Zend\ServiceManager\Exception\InvalidServiceNameException' with message 'A service by the name or alias "Zend\Authentication\AuthenticationService" already exists and cannot be overridden; please use an alternate name' in C:\xampp1\htdocs\zf2\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php: "

請誰能幫助我!

回答

2

您遇到的錯誤非常明顯。它表示您正嘗試使用已在ZF2中存在的名稱Zend\Authentication\AuthenticationService註冊您的服務。你必須替換名字。

讓這發生在你的module.config.php

'service_manager' => array(
    'factories' => array(
     'AuthStorage' => 'SanAuthWithDbSaveHandler\Factory\Storage\AuthStorageFactory', 
    ), 
    'aliases' => array(// make sure "aliases" and not "alias" 
     'Zend\Authentication\AuthenticationService' => 'my_auth_service', 
    ), 
    'invokables' => array(
     'my_auth_service' => 'SanAuthWithDbSaveHandler\Factory\Storage\AuthenticationServiceFactory', 
    ), 
), 
+0

我已經試過了,還是同樣的錯誤。我不知道我做錯了什麼。肯定有東西 –

+0

你試過重命名你的服務嗎? –

+0

不!你可以租賃告訴我更多細節嗎?我是否將其重命名爲「module.config.php?」 –