[英]Symfony 3 FosUserBundle edit profile
I try to edit user by administrator in backend (username, password, custom fields) : 我尝试通过管理员在后端(用户名,密码,自定义字段)中编辑用户:
$form = $this->createForm(UserEditType::class, $idUser, array('class' => 'AppBundle/Entity/User'));
if ($request->getMethod() == 'POST') {
$form->handleRequest($request);
if ($form->isValid()) {
$this->get('fos_user.user_manager')->updateUser($idUser);
return $this->redirect($this->generateUrl('user_liste'));
}
}
return $this->render(':User:userEdit.html.twig', array('form' => $form->createView()));
But I have an error : 但是我有一个错误:
Warning : Missing argument 1 for AppBundle\\Form\\User\\UserEditType::__construct()
警告 :AppBundle \\ Form \\ User \\ UserEditType :: __ construct()缺少参数1
My userEdittype : 我的userEdittype:
<?php
namespace AppBundle\Form\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Validator\Constraints\NotBlank;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use FOS\UserBundle\Form\Type\RegistrationFormType as BaseRegistrationFormType;
class UserEditType extends BaseRegistrationFormType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('nom', TextType::class, array(
'constraints' => array(
new NotBlank(),
)
)
)
->add('prenom', TextType::class, array(
'constraints' => array(
new NotBlank(),
)
)
);
}
public function getBlockPrefix()
{
return 'app_user_profile';
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array('data_class' => 'AppBundle\Entity\User'));
}
}
The default FOS\\UserBundle\\Form\\Type\\RegistrationFormType::__construct
require a the User
class name as an argument. 默认的
FOS\\UserBundle\\Form\\Type\\RegistrationFormType::__construct
需要使用User
类名称作为参数。 Since you already provided it inside configureOptions
, you can override the __construct of your UserEditType
. 由于您已经在
configureOptions
内部提供了它,因此可以覆盖UserEditType
的__construct。
class UserEditType extends BaseRegistrationFormType
{
public function __construct(/* nothing */)
{
}
// ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.