我找不到错误原因
I couldn't find error reason
我正在尝试在 symfony2 中创建一个简单的博客。但不幸的是,我在尝试在 symfony2 中创建表单时遇到问题,代码如下
<?php
/**
* Created by PhpStorm.
* User: kanat
* Date: 2/13/16
* Time: 8:11 PM
*/
namespace Blogger\BlogBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class EnquiryType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name');
$builder->add('email', 'email');
$builder->add('subject');
$builder->add('body', 'textarea');
}
public function getName()
{
return 'contact';
}
}
位于Blogger\BlogBundle\Form\EnquiryType。php
错误是:
Expected argument of type "string", >"Blogger\BlogBundle\Form\EnquiryType" given
我不知道如何解决这个问题。请帮助我
您的版本,但错误:
$form = $this->createForm(new EnquiryType(), $yourEntity);
您必须使用:
$form = $this->createForm(EnquiryType::class, $yourEntity);
控制器:
public function contactAction() {
$enquiry = new Enquiry();
$form = $this->createForm(EnquiryType::class, $enquiry);
我正在尝试在 symfony2 中创建一个简单的博客。但不幸的是,我在尝试在 symfony2 中创建表单时遇到问题,代码如下
<?php
/**
* Created by PhpStorm.
* User: kanat
* Date: 2/13/16
* Time: 8:11 PM
*/
namespace Blogger\BlogBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class EnquiryType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name');
$builder->add('email', 'email');
$builder->add('subject');
$builder->add('body', 'textarea');
}
public function getName()
{
return 'contact';
}
}
位于Blogger\BlogBundle\Form\EnquiryType。php 错误是:
Expected argument of type "string", >"Blogger\BlogBundle\Form\EnquiryType" given
我不知道如何解决这个问题。请帮助我
您的版本,但错误:
$form = $this->createForm(new EnquiryType(), $yourEntity);
您必须使用:
$form = $this->createForm(EnquiryType::class, $yourEntity);
控制器:
public function contactAction() {
$enquiry = new Enquiry();
$form = $this->createForm(EnquiryType::class, $enquiry);