だから私はフォームタイプ「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?"
誰かが私を助けることができます:(?