gpt4 book ai didi

symfony2表单bindRequest返回500错误

转载 作者:行者123 更新时间:2023-12-02 15:55:26 25 4
gpt4 key购买 nike

所以我有一个表单类型“PictureType”:

<?php

namespace AB\MyBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

class PictureType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder ->add('picture','file');
}

public function getName()
{
return 'ab_mybundle_picturetype';
}

public function useDefaultOptions(array $options)
{
return array(
'data_class' => 'AB\MyBundle\Form\Model\Picture'
);
}
}

实体图片:

<?php

namespace AB\MyBundle\Form\Model;
use Symfony\Component\Validator\Constraints as Assert;

class Picture
{

/**
* @Assert\Image(maxSize="800000")
*/

public $picture;

}

Controller :

use AB\MyBundle\Form\Type\PictureType;
use AB\MyBundle\Form\Model\Picture;
...
...

$form = $this->createForm(new PictureType, new Picture);
if( $this->get('request')->getMethod() == 'POST' )
{
echo "1"; // 1 is printed
$form->bindRequest($this->get('request')); // this line gives the error

echo "2"; // 2 is not printed
if( $form->isValid() )
{

}
}

return $this->render("ABMyBundle:Default:pic.html.twig",array(
'form' => $form->createview()

));

当我提交表单时,它给我一个 500 错误

"The controller must return a response (null given). Did you forget to add a return statement somewhere in your controller?" 

有人可以帮助我吗:(?

最佳答案

$form = $this->createForm(new PictureType, new Picture); 
if( $this->get('request')->getMethod() == 'POST' )
{
echo "1";
$form->bind($request);
if( $form->isValid() )
{
echo "2";
}
}

引用链接: http://symfony.com/blog/form-goodness-in-symfony-2-1 https://github.com/symfony/symfony/pull/4811

关于symfony2表单bindRequest返回500错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16920489/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com