我正在努力将我的代码更新为Symfony3标准,但是我的一些表单遇到了一些问题。我尝试了几件事,但没有任何工作。
在我的树枝上:
<form action="{{ path('paces_colle_gestioncsv_imprimer',
{ 'id' : document.id }) }}" method="post" {{ form_enctype(form) }}>
</form>
自Symfony 2.8以来,{{form_enctype}}已被弃用。我必须获得控制器的路径才能将其更改为{{form_start}}
在我的控制器中:
public function ajouterErrataAction($id)
{
$em = $this->getDoctrine()->getManager();
$document = $em->getRepository('PACESColleBundle:DocumentCSV')->find($id);
if(!$document){
throw $this->createNotFoundException('Document inexistant');
}
$colle = $document->getColle();
$form = $this->createForm(ajouterErrataType::class);
return $this->render('PACESColleBundle:Classement:ajouterErrata.html.twig', array(
"colle" => $colle,
"document" => $document,
"form" => $form->createView()
));
}
我的formType:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('errata', TextareaType::class, array('required' => false,
'attr' => array('class'=>'ckeditor')
))
->add('precision', TextareaType::class, array('required' => false,
'attr' => array('class'=>'ckeditor')))
->add('submit',SubmitType::class, array('label' => 'Imprimer'));
;
}
答案 0 :(得分:1)
您可以覆盖控制器或模板中的操作: http://symfony.com/doc/current/book/forms.html#changing-the-action-and-method-of-a-form 你试过吗?
答案 1 :(得分:0)
您可以像这样设置操作路径:
$form = $this->createForm(ajouterErrataType::class, $data, [
'action' => $this->generateUrl(''paces_colle_gestioncsv_imprimer', ['id' => $document->getId()]),
'method' => 'POST',
]);
答案 2 :(得分:0)
Symfony 3的做法就像this:
./spark-ec2 --key-pair=octavianKey4 --identity-file=credentials3.csv --region=eu-west-1 --zone=eu-west-1c launch my-instance-name