MVCの概念では、モデルはアプリケーションのビジネス部分を表します。
認証の管理、ユーザーの保存、削除、アクティブ化はビジネス上の問題です。
したがって、ユーザーモデルで直接認証、保存、削除、アクティブ化するメソッドを作成することは理にかなっています。
したがって、ユーザーモデルでは、静的メソッドを次のように実装することが望ましいです。
public static function authenticate ($ username, $ password)
{
$authService = $this-> getServiceLocator()->get('Zend\Authentication\AuthenticationService');
$adapter = $authService->getAdapter();
$adapter->setIdentityValue($username);
$adapter->setCredentialValue($password);
$authResult = $authService->authenticate();
return $authResult->isValid();
}
また、コントローラーでは、次のことを直接行うことができます。
User/Entity/User::authenticate($username, $password);