所以我有一个表单类型“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;
}
控制器:
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?"
有人能帮我吗 :( ?