简体   繁体   中英

Symfony REST bundle: add date to QueryParam requirements

How would you require a valid DateTime string inside Symfony's REST bundle's @QueryParam annotation?

I have this now: @QueryParam(name="createdFrom", requirements="2016-05-18T12:00:00+0000")

I would like to use a regex that represents a valid date time format.

you can do this way:

@QueryParam(name="createdFrom", nullable=false, requirements="(19|20)[0-9][0-9]-(0[0-9]|1[0-2])-(0[1-9]|([12][0-9]|3[01]))T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]?[+|-][0-9][0-9][0-9][0-9]") 

Should work fine.

This above regex works for: 2016-05-18T12:00:00+0000

This site you can use to test your regex: http://www.regexpal.com/1966

In this site has some samples of regex date: http://www.regexlib.com/Search.aspx?k=datetime&c=0&m=0&ps=20&p=2

Best Regards

else :

/**
 * @Route("/blog/archive/{start}/{end}")
 * @ParamConverter("start", options={"format": "Y-m-d"})
 * @ParamConverter("end", options={"format": "Y-m-d"})
 */
public function archiveAction(\DateTime $start, \DateTime $end)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM