Symfony3/PHP7表格提交不';行不通
我试图创建一个简单的表单,它可以执行数据库查询并在数据库中插入一些数据。但是问题是表单没有提交(?),Symfony3/PHP7表格提交不';行不通,php,mysql,forms,symfony,Php,Mysql,Forms,Symfony,我试图创建一个简单的表单,它可以执行数据库查询并在数据库中插入一些数据。但是问题是表单没有提交(?),$form->isSubmitted()总是错误的 use Symfony\Component\Form\Extension\Core\Type\TextType as TextTypeForm; use Symfony\Component\Form\Extension\Core\Type\SubmitType as SubmitTypeForm; 任务类: <?php namesp
$form->isSubmitted()
总是错误的
use Symfony\Component\Form\Extension\Core\Type\TextType as TextTypeForm;
use Symfony\Component\Form\Extension\Core\Type\SubmitType as SubmitTypeForm;
任务类:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="task")
*/
class Task
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
private $id;
/**
* @ORM\Column(type="string")
*/
private $title;
/**
* @ORM\Column(type="string")
*/
private $description;
/**
* @ORM\Embedded(class = "Status")
*/
private $status;
public function addTask(string $title, string $desc, bool $urgent, bool $important){
$em = $this->getDoctrine()->getManager();
$product = new Task();
$product->setTitle($title);
$status = new Status($urgent,$important);
$product->setStatus($status);
$product->setDescription($desc);
$em->persist($product);
$em->flush();
} // "addtask" [POST] /create
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* @param string $title
*
* @return Task
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set description
*
* @param string $description
*
* @return Task
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set status
*
* @param integer $status
*
* @return Task
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
/**
* Get status
*
* @return int
*/
public function getStatus()
{
return $this->status;
}
在我看来,您定义了错误的类型。
TextTypeForm和SubmitTypeForm是未知类型
$form = $this->createFormBuilder($task)
->setMethod("POST")
->add('title', TextTypeForm::class)
->add('description', TextTypeForm::class)
->add('save', SubmitTypeForm::class, array('label' => 'Create Task'))
->getForm();
应该是
$form = $this->createFormBuilder($task)
->setMethod("POST")
->add('title', TextType::class)
->add('description', TextType::class)
->add('save', SubmitType::class, array('label' => 'Create Task'))
->getForm();
在我看来,您定义了错误的类型。
TextTypeForm和SubmitTypeForm是未知类型
$form = $this->createFormBuilder($task)
->setMethod("POST")
->add('title', TextTypeForm::class)
->add('description', TextTypeForm::class)
->add('save', SubmitTypeForm::class, array('label' => 'Create Task'))
->getForm();
应该是
$form = $this->createFormBuilder($task)
->setMethod("POST")
->add('title', TextType::class)
->add('description', TextType::class)
->add('save', SubmitType::class, array('label' => 'Create Task'))
->getForm();
你确定你通过了try吗?在我没有使用try之前,它仍然不起作用,也没有任何错误删除它,从未在try and catch中看到HandlerRequest。你还有其他东西可以帮助我们吗?即使使用Removed,仍然不起作用。你可以显示任务类吗?你确定你通过了试用吗?在我没有使用试用之前,它仍然不起作用,也没有任何错误。删除它,从未在任何地方看到过试用和捕获中的HandlerRequest。你还有什么可以帮助我们的吗?即使使用Removed,仍然不起作用。你能展示任务类吗?对不起,我没有提到,但是我想类型是可以的。TextType作为TextTypeForm;SubmitType作为SubmitTypeForm;这有什么用呢?我不能让TextType声明两次,请使用条令\DBAL\Types\TextType;对不起,我没提,但我想类型是可以的。TextType作为TextTypeForm;SubmitType作为SubmitTypeForm;这有什么用呢?我不能让TextType声明两次,请使用条令\DBAL\Types\TextType;