我尝试通过 Symfony (3.2) 中的表单验证来验证日期(或日期时间)。
我正在使用 FOSRestBundle 来使用请求中的 json (因为我尝试开发我的个人 API)
但我尝试了很多格式:
但表单无效,我总是收到此错误:此值无效
我的控制器的功能
public function postPlacesAction(Request $request) {
$place = new Place();
$form = $this->createForm(PlaceType::class, $place);
$form->handleRequest($request);
if ($form->isValid()) {
return $this->handleView($this->view(null, Response::HTTP_CREATED));
} else {
return $this->handleView($this->view($form->getErrors(), Response::HTTP_BAD_REQUEST));
}
}
Run Code Online (Sandbox Code Playgroud)
我的实体
class Place
{
/**
* @var string
*
* @Assert\NotBlank(message = "The name should not be blank.")
*/
protected $name;
/**
* @var string
*
* @Assert\NotBlank(message = "The address …Run Code Online (Sandbox Code Playgroud)