我想在自定義窗體字段類型中獲取當前用戶。可捕獲的致命錯誤:傳遞給UserBundle Form UserType :: __ construct()的參數2必須是實例?
我formType
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
class UserType extends AbstractType {
protected $doctrine;
protected $tokenStorage;
public function __construct($doctrine,TokenStorageInterface $tokenStorage)
{
$this->tokenStorage = $tokenStorage;
$this->doctrine = $doctrine;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$user = $this->tokenStorage->getToken()->getUser();
$builder
->setAction($options['data']['url'])
->setMethod('GET')
->add('userType', 'choice', array('choices' => array(
'userType_p' => $pId,
'userType_t' => $tId),
'choices_as_values' => true, 'label' => 'Usertype ',
'expanded' => true, 'multiple' => true,
'translation_domain' => 'User',))........
....
這裏是我的服務:
user.form.token:
class: UserBundle\Form\UserType
arguments: ['@security.token_storage']
tags:
- { name: form.type }
在控制器我打電話這樣的形式:
$form = $this->createForm(new UserType($em,$this->get('user.form.token')), $data....
我得到這個以下錯誤:
Catchable Fatal Error: Argument 2 passed to UserBundle\Form\UserType::__construct() must implement interface Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface, none given, called in......