你好,我有一个博客,其中有文章,我想在一篇文章中发布一个小时的手册,例如,如果我们是19/07/2018,我想在7月25日下午3:30发布文章
我的实体中有一个dateTime类型的属性
/**
* @ORM\Column(type="date", nullable=true)
*/
private $isPublished;
我的控制器,允许我显示文章
/**
* @Route("/", methods="GET|POST")
* @param Request $request
* @return Response
*/
public function index(Request $request): Response {
$cookie = 'Bienvenue sur mon site web';
setcookie('Al-houria.com', $cookie, time()+31536000, null, null, false, true);
$em = $this->get('doctrine.orm.entity_manager');
$dql = "SELECT a FROM App:Articles a ORDER BY a.createdAt DESC";
$query = $em->createQuery($dql);
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$query, /* query NOT result */
$request->query->getInt('page', 1)/*page number*/,
10/*limit per page*/
);
return $this->render('index.html.twig', [
'title' => 'Parce qu\'écrire est une liberté',
'description' => 'Bienvenue sur Al-Houria.fr le blog culture et humeur d\'une passionnée du Moyen Orient.',
'keywords' => 'Blog, Al-houria, Articles, Mondes, Actualité, Culture',
'pagination' => $pagination
]);
}
您认为我该如何只显示当前日期的文章,并显示其他文章的日期分别
衷心感谢您的帮助
答案 0 :(得分:1)
我认为日期在请求中。这是您通过日期传递方法来调用日期的方式。
df <- read.table(text =
"TREE_ID PM_Date variable value
2013000584 2013-04-02 elm 0
2013000498 2013-06-11 elm 1
2013000123 2013-09-03 maple 0
2013000642 2014-02-15 maple 0
2013000778 2016-07-08 maple 1", header = T)
获取日期后,可以在查询中使用它。
答案 1 :(得分:1)
有效!!!!
/**
* @Route("/", methods="GET")
* @param Request $request
* @return Response
*/
public function index(Request $request): Response {
$cookie = 'Bienvenue sur mon site web';
setcookie('Al-houria.com', $cookie, time()+31536000, null, null, false, true);
$em = $this->get('doctrine.orm.entity_manager');
//SELECT * FROM articles WHERE published_at <= NOW() ORDER BY created_at DESC
$dql = "SELECT a FROM App:Articles a WHERE a.publishedAt <= :date ORDER BY a.createdAt DESC";
$query = $em->createQuery($dql);
$query->setParameter('date', new \DateTime("now", new \DateTimeZone('Europe/Paris')));
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$query, /* query NOT result */
$request->query->getInt('page', 1)/*page number*/,
10/*limit per page*/
);
return $this->render('index.html.twig', [
'title' => 'Parce qu\'écrire est une liberté',
'description' => 'Bienvenue sur Al-Houria.fr le blog culture et humeur d\'une passionnée du Moyen Orient.',
'keywords' => 'Blog, Al-houria, Articles, Mondes, Actualité, Culture',
'pagination' => $pagination
]);
}