0
symfonyの拡張機能でdoctrineを呼び出してログインする必要があります。symfonyは現在のログインユーザを取得するために複数の引数を拡張機能に追加します
これは私のサービスYML私の場合は
twig.extension.app:
class: AppBundle\Twig\AppExtension
arguments:
$doctrine : '@doctrine'
$context : '@security.context'
tags:
- { name: twig.extension }
twig.extension.auth:
class: AppBundle\Twig\AuthExtension
arguments:
$doctrine : '@doctrine'
$context : '@security.context'
tags:
- { name: twig.extension }
ですが、私はそれは2つの拡張であることをdevide。
が、これは私の拡張機能である:
<?php
namespace AppBundle\Twig;
use Symfony\Bridge\Doctrine\RegistryInterface;
use Symfony\Component\Security\Core\Security;
class AuthExtension extends \Twig_Extension
{
protected $doctrine;
protected $context;
public function __construct(RegistryInterface $doctrine, Security $context)
{
$this->doctrine = $doctrine;
$this->context = $context;
}
}
が、私はエラーだ:私は教義を必要とし、また、現在のユーザーでログインした状態で、
[Symfony\Component\DependencyInjection\Exception\AutowiringFailedException]
Cannot autowire service "AppBundle\Twig\AppExtension": argument "$context" of method "__construct()" references class "Symfony\Component\Security\Core\Security" but no such service exists. It cannot be auto-registered because it is from a different root namespace.
どのようにこれを解決するの?
ログインしたユーザーにsecurity.token_storageを使用する前に、security.contextを見たことがありません。セキュリティバンドルでフルフレームワークを使用していますか? – Cerad