2017-11-28 2 views
0

데이터베이스 쿼리를 실행하고 데이터를 데이터베이스에 삽입 할 수있는 간단한 양식을 만들려고합니다. 그러나 문제는 양식이 제출되지 않고 (?), $form->isSubmitted()은 항상 거짓입니다. Symfony3/PHP7 양식 제출이 작동하지 않습니다.

use Symfony\Component\Form\Extension\Core\Type\TextType as TextTypeForm; 
use Symfony\Component\Form\Extension\Core\Type\SubmitType as SubmitTypeForm; 


public function renderFormAction(Request $request){ 
    $task = new Task(); 
    $task->setTitle('Keyboard'); 
    $task->setDescription('Ergonomic and stylish!'); 

    $form = $this->createFormBuilder($task) 
     ->setMethod("POST") 
     ->add('title', TextTypeForm::class) 
     ->add('description', TextTypeForm::class) 
     ->add('save', SubmitTypeForm::class, array('label' => 'Create Task')) 
     ->getForm(); 



    try { 
     $form->handleRequest($request); 
    } catch (\Exception $e) { 
     echo "failed : ".$e->getMessage(); 
    } 

    if ($form->isSubmitted()) { 
     $data = $form->getData(); 
     $em->persist($task); 
     $em->flush(); 

     return $this->redirectToRoute('task_success'); 
    } 

    return $this->render('eisenhover/addtask.html.twig', array(
     'form' => $form->createView(), 
    )); 
} 

작업 클래스 :

<?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; 
} 

}

+0

당신에게 당신이 통과하려고 확신해야 하는가? –

+0

전에 try를 사용하지 않고 여전히 작동하지 않았으며 오류가 없습니다. – shaelex

+0

제거하고 어디에서나 handleRequest를 보지 못했습니다. 도와 줄 다른 것이 있습니까? –

답변

4

가 잘못된 유형 http://symfony.com/doc/current/reference/forms/types.html 정의 나에게 보인다.
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(); 
+0

죄송합니다. 언급하지는 않았지만 형식이 괜찮습니다. TextType 형식의 TextType; SubmitType으로 SubmitType; – shaelex

+0

그 유틸리티는 무엇입니까? –

+0

Doctrine \ DBAL \ Types \ TextType을 사용하여 TextType을 두 번 선언 할 수 없습니다. – shaelex

관련 문제