2017-06-27 1 views
0

ZF3の認証サービスは引き続き利用できますか?そうでなければ、新しいものの名前は何ですか?それは同じように機能しますか?Zend Framework 3の認証サービス

私は、エラーメッセージが表示されます。

クラスのインポート\ AuthenticationServiceは「

を見つけていない、私はそれをつかむために作曲を頼ま:

composer

私も検索それはzend-framework.comで、私は移行トピックのいずれかの情報を見つけることができませんでした。

私はZF1から来ているので、私の考えが正しいかどうかも質問したいと思います。私は私のModule.phpの工場としてauthenticationServiceを実装:次のように

Controller\IndexController::class => function($container) { 
         return new Controller\IndexController(
           $container->get(Model\UserTable::class), 
           $container->get(Model\Authentication::class), 
           $container->get(AdapterInterface::class) 
           ); 
        }, 

Indexcontrollerに見える私:私は私のコントローラ(Module.php)に認証サービスを接続

'factories' => [ 

        Model\Authentication::class => function ($container){ 
         $auth = new AuthenticationService(); 
         $dbAdapter = $container->get(AdapterInterface::class); // AND aktiv != 0 
         $dbTableAuthAdapter = new DbTableAuthAdapter($dbAdapter, 't_user','accessname','password', 'SHA2(?, 512)'); 
         $auth->setAdapter($dbTableAuthAdapter); 
         return $auth; 
        }, 

class IndexController extends AbstractActionController 
{ 
    private $loginTable; 
    private $authService; 
    private $db; 

public function __construct(UserTable $loginTable, AuthenticationService $authService, AdapterInterface $db) 
{ 
    //$db=$this->db ; 
    $this->loginTable = $loginTable; 
    $this->authService = $authService; 
    $this->db=$db; 
} 

//Anzeigen der importierten Dateien 
public function indexAction() 
{ 
    $berechtigung = (int) $this->loginTable->getBerechtigung($this->authService->getIdentity()); 
    if(!$this->authService->hasIdentity() || $berechtigung > 1){ // 1 = Administrator 
     return $this->redirect()->toRoute('user', ['action' => 'login']); 
    } 
    else { 

     return $this->redirect()->toRoute('project', ['action' => 'index']); 
    } 

} 

これは認証を実装する適切な方法ですか?

答えて

2

は、Zendの認証は、ユーザーの端末

composer require zendframework/zend-authentication 

にそしてこの

クラスのようなエラー・メッセージについては、これを入力してくださいインストールするには 'インポート\ AuthenticationService' が見つかりません

ますこのような完全な名前空間で使用する必要があります

use Zend\Authentication\AuthenticationService; 
+0

私の工場では別の問題があるかもしれません。$ dbTableAuthAdapter = new DbTableAuthAdapter($ dbAdapter、 't_user'、 'accessname'、 'password'); DbTableAuthAdapterも見つかりませんでした。理由は分かりますか? –

+0

ソースコードにこれを加える 'Zend \ Authentication \ Adapter \ DbTableをDbTableAuthAdapterとして使用する;' –