getServiceConfig()
のようなAuthenticationService
オブジェクトを作成して Zend Auth を実装しましたModule.php
。
'AuthService' => function($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$dbTableAuthAdapter = new DbTableAuthAdapter($dbAdapter, 'tblUSRUsers', 'Email', 'Password', "MD5(?)");
$authService = new AuthenticationService();
$authService->setAdapter($dbTableAuthAdapter);
$authService->setStorage($sm->get('Application\Model\MyAuthStorage'));
return $authService;
},
コントローラーアクションでは、このオブジェクトを取得しています
$this->getServiceLocator()
->get('AuthService');
認証のために、次を使用して値を取得します
$authservice = $this->getServiceLocator()->get('AuthService');
$arrUserDetails = $authservice->getIdentity();
これらの値は利用可能です。
しかし、問題はServiceLocator
Controller コンストラクターで使用できないため、上記のコードをそこに記述できないことです。すべてのアクションでこのコードを記述することは、良い習慣ではないようです。誰でもこれを手伝ってもらえますか?