Symfony2 如何从控制器文件中访问该字段的月份

Symfony2 How access the months of this field from the Controller file

我在数据库 table "dateinscription" 中有一个 "datetime" 类型的字段 我想从控制器文件中访问这个字段的月份

如果我们假设您有一个实体用户作为示例,希望您有日期题词属性,您需要在控制器中像这样从数据库中获取用户对象:

//get the entity manager
$em = $this->getDoctrine()->getManager();
//get your object : we supposed that dateinscription is an attribute from user entity
$user = $em->getRepository(YouFolder/UserBundle/Entity/User)->find(Id of the user);
//get inscription date
$dateinscription = $user->getDateInscription();
//get Month as string exemple 06
$month = $dateinscription->format('m');