[英]I couldn't find error reason
I'm trying to create a simple blog in symfony2 . 我正在尝试在symfony2中创建一个简单的博客。 But unfortunately I'm having a problem while trying to create a form in symfony2 the code is below 但是不幸的是,我尝试在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';
}
}
which situated Blogger\\BlogBundle\\Form\\EnquiryType.php the error is : 其中位于Blogger \\ BlogBundle \\ Form \\ EnquiryType.php的错误是:
Expected argument of type "string", >"Blogger\\BlogBundle\\Form\\EnquiryType" given 给定类型为“ string”,>“ Blogger \\ BlogBundle \\ Form \\ EnquiryType”的预期参数
I have no idea how to fix that . 我不知道该如何解决。 Please help me 请帮我
Your version, but error: 您的版本,但错误:
$form = $this->createForm(new EnquiryType(), $yourEntity);
You must use: 您必须使用:
$form = $this->createForm(EnquiryType::class, $yourEntity);
Controller : 控制器 :
public function contactAction() {
$enquiry = new Enquiry();
$form = $this->createForm(EnquiryType::class, $enquiry);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.