0
我剛開始用symfony形式,我不明白,爲什麼我得到這個類型的錯誤: screen from profiler這個createForm參數有什麼問題?
所以schould我通過什麼作爲參數,使其正常工作? 下面是RegisterController我的代碼:
/**
* @Route("/register", name="register")
*/
public function showRegisterAction()
{
$registration = new User();
$form = $this->createForm(new Register(), $registration, ['action' => $this->generateUrl('create'), 'method' => 'POST']);
return $this->render("/login/register.html.twig", ['form' => $form->createView()]);
}
我與fromBuilder註冊類代碼:
class Register extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name', 'text', ['label' => 'USERNAME'])
->add('mail', 'email', ['label' => 'email'])
->add('password', 'password', ['label' => 'password'])
->add('password_repeat', 'password', ['mapped' => false, 'label' => 'confirm'])
->add('company', 'text', ['label' => 'company'])
->add('nip', 'text', ['label' => 'nip'])
->add('street', 'text', ['label' => 'street'])
->add('street_nr', 'text', ['label' => 'street_nr'])
->add('postal_code', 'text', ['label' => 'postal_code'])
->add('city', 'text', ['label' => 'city'])
->add('tel', 'text', ['label' => 'tel'])
->getForm();
}
public function getName()
{
return "register";
}
public function setDefaultOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(['data_class' => 'AppBundle\Entity\User']);
}
}
感謝您的幫助:)! – Eddy
不客氣。另外請注意,在創建表單類時,您不需要'getForm()'FormBuilder的方法。 –