2012-09-24 31 views
1

我正在嘗試使用symfony2登錄名。我有我的實體類連接到數據庫。在我的表格中,我只有用戶的電子郵件,這是用戶名。我應該使用getUsername()方法知道我沒有真正的用戶名。Symfony2:實現UserInterface的用戶實體類:使用電子郵件而不是用戶名

當我試圖刪除這個方法,我在歌廳一個致命的錯誤消息:

Fatal error: Class MDPI\BackendBundle\Entity\Users contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Symfony\Component\Security\Core\User\UserInterface::getUsername) in /home/milos/workspace/mdpi-login2/src/MDPI/BackendBundle/Entity/Users.php on line 768 

我應該使用

getUsername() 
{ 
    return this->email; 
} 

還是有這樣做的更好的方式???

謝謝。

回答

2

使用原生的Symfony SecurityBundle,你只需要指定app/config/security.yml你作爲登錄字符串中使用的實體領域,:

security: 

    encoders: 
     MDPI\BackendBundle\Entity\User: plaintext 

    providers: 
     entity: 
      entity: { class: MDPI\BackendBundle\Entity\User, property: email } 

    firewalls: 
     ... 
+0

謝謝@ PECE,與,將電子郵件,而不是檢查用戶名? –

相關問題