根据日期限制对页面的访问

时间:2016-01-20 13:32:22

标签: symfony

我想根据数据库中的日期存储来限制对页面的访问。例如,我希望以下所有路线:monsite.fr/mon_compte/检查日期条件。我只是想知道symfony2是否有更好的方法来做到这一点?

提前Ty:)

1 个答案:

答案 0 :(得分:0)

也许是这样的:

    public function indexAction()
{
    $user = $this->get('security.token_storage')->getToken()->getUser();
    $dates = $this->getDoctrine()->getManager()->getRepository('AcmeCoreBundle:DateAce')->getAuthorizationDate($user->getId());

    $now = new DateTime();

    if($dates->debut() < $now < $dates->fin())
    {
        throw new AccessDeniedException;
    }

}
相关问题