私は現在ログインしているユーザーを取得する必要がある教義リスナーを持っています。 symfony 3 Doctrine LIstenerサービスインジェクションtoken_storage doesnt work
class DoctrineListener
{
/**
* @var null|TokenInterface
*/
private $token;
/**
* DoctrineListener constructor.
*
* @param TokenStorageInterface $tokenStorage
*/
public function __construct(TokenStorageInterface $tokenStorage)
{
$this->token = $tokenStorage->getToken();
var_dump($this->token);
}
と私のservice.ymlで
:私はこのリスナーにそれを使用しようとすると、doctrine.listener:
class: AppBundle\EventListener\DoctrineListener
arguments:
- '@security.token_storage'
public: false
tags:
- { name: doctrine.event_listener, event: preFlush, method: preFlush }
ダンプはいつも私はnullを返します。 私はtoken_storage_serviceを他のサービスに注入します。うまく機能します。
私はsymfony 3.1の下で、残りのAPIを使用しています。 そして私は郵便配達員と私の認証ヘッダーを送ります。
誰かが自分のコードで何が問題なのか教えていただけますか?
ありがとうございます。
ここをクリックしてください:http://stackoverflow.com/questions/39332767/symfony-get-connected-user-id-from-entity –
セキュリティリスナーが(まだ)実行されていないためnullが返されます – Federkun
ありがとう@アルフォンセ、これも私を助けてくれた:) –