![](/img/trans.png)
[英]Symfony 3 FOSUserBundle redirect to login after submiting edit profile
[英]Symfony 3 FosUserBundle edit profile
我嘗試通過管理員在后端(用戶名,密碼,自定義字段)中編輯用戶:
$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()));
但是我有一個錯誤:
警告 :AppBundle \\ Form \\ User \\ UserEditType :: __ construct()缺少參數1
我的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'));
}
}
默認的FOS\\UserBundle\\Form\\Type\\RegistrationFormType::__construct
需要使用User
類名稱作為參數。 由於您已經在configureOptions
內部提供了它,因此可以覆蓋UserEditType
的__construct。
class UserEditType extends BaseRegistrationFormType
{
public function __construct(/* nothing */)
{
}
// ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.