私は、Zend 2とDoctrine 2の認証に関するチュートリアルを探しています。 特に、コントローラとアダプタの作成。Zend 2 + doctrine 2認証アダプタ
公式文書はあまりにもグローバルではありません。
はあなたに感謝編集:私は "教義エンティティ" を使用
(名前空間のユーザー\エンティティ;)
エンティティがmodule.config.phpファイルに登録している:
'doctrine' => array(
'driver' => array(
__NAMESPACE__ . '_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity')
),
'orm_default' => array(
'drivers' => array(
__NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
)
)
),
)
しかし、私のIDClassキーをアダプタに向けるにはどうしたらいいですか? コントローラ:\ SRC \ DoctrineModule \オプション\ AuthenticationAdapter.php上の非オブジェクトで...教義\ドクトリンモジュール上のメンバ関数getRepository(の呼び出し):
use Zend\Mvc\Controller\AbstractActionController,
Zend\View\Model\ViewModel,
Zend\Authentication\AuthenticationService,
Doctrine\ORM\EntityManager,
DoctrineModule\Authentication\Adapter\ObjectRepository as DoctrineAdapter,
User\Entity\User,
User\Form\UserForm;
class UserController extends AbstractActionController
{
protected $em;
public function setEntityManager(EntityManager $em)
{
$this->em = $em;
}
public function getEntityManager()
{
if (null === $this->em)
$this->em = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
return $this->em;
}
public function getRepository()
{
if (null === $this->em)
$this->em = $this->getEntityManager()->getRepository('User\Entity\User');
return $this->em;
}
public function loginAction()
{
....
????????????
$adapter = new DoctrineAdapter();
$adapter->setIdentityValue($username);
$adapter->setCredentialValue($password);
$auth = new AuthenticationService();
$result=$auth->authenticate($adapter);
????????????
}
}
私はこのエラーを持っています行132 行123:$ this-> objectManager-> getRepository($ this-> identityClass)を返します。
こんにちは、ありがとう、ヒント。 DoctrineAdapterとしてDoctrineModule \ Authentication \ Adapter \ ObjectRepositoryを使用しようとしています。 しかし、$ result = $ adapter-> authenticate()を呼び出すと、このエラーが発生します。非オブジェクト上のメンバ関数getRepository()を呼び出します。どのようにして私のidentityClassを定義しますか? – beweed
あなたのIDクラスはDoctrine Document(ODMの場合)またはDoctrine Entity(ORMの場合)でなければなりません。ドキュメント/エンティティと同じように定義します。 (他のすべてのドキュメント/エンティティの場合と同様に、 'module.config.php'にドライバキーを使ってドキュメント/エンティティを登録することを忘れないでください)。アイデンティティクラスを作成したら、そのアイデンティティクラスを指すために 'identityClass'キーを使います。上記の例では、アイデンティティクラスは 'Application \ Model \ User'ですが、あなたが好きなものを作ることができます。 – superdweebie
本当にありがとうございます。私はちょうど私の問題を見つけた私の投稿を編集する。 – beweed