我正在开发一个Symfony 2.6.1应用程序,我有一个使用FormTypes呈现的表单和一个使用注释作为验证的实体.表单被提交给FOSRestController的AJAX POST调用.事情是isValid()函数返回FALSE并且我没有收到错误消息...
我的FOSRestController看起来如下:
class RestGalleryController extends FOSRestController{
/**
* @Route(requirements={"_format"="json"})
*/
public function postGalleriesAction(\Symfony\Component\HttpFoundation\Request $request){
return $this->processForm(new \Law\AdminBundle\Entity\Gallery());
}
private function processForm(\Law\AdminBundle\Entity\Gallery $gallery){
$response = array('result' => 'Default');
$gallery->setName('TEST'); //Just added this to be sure it was a problem with the validator
$form = $this->createForm(
new \Law\AdminBundle\Form\Type\GalleryType(),
$gallery
);
$form->handleRequest($this->getRequest());
if ($form->isValid()) {
$response['result'] = 'Is Valid!';
}else{
var_dump( $form->getErrorsAsString() );
die;
}
return $response;
}
Run Code Online (Sandbox Code Playgroud)
我的图库实体课程如下:
<?php
namespace Law\AdminBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use …Run Code Online (Sandbox Code Playgroud)