3

だから私はフォームタイプ「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?" 

誰かが私を助けることができます:(?

4

2 に答える 2

2
$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

于 2013-06-26T05:53:10.483 に答える