Phalcon的博客档案

时间:2016-04-18 11:46:56

标签: jquery blogs archive phalcon

我正在尝试使用phalcon创建博客存档。但我无法完美地理解它。在我的博客表中我有一个字段日期时间,就像“2016-04-15 23:08:40”这种格式。我无法分开年,月,日和时间。我怎么能序列化呢?或者如何进行查询?我现在只是一个简单的查询。

[控制器]

public function indexAction()
{
    $bloger = Blogs::find();
    $this->view->setVar('counts', count($bloger));
    $this->view->setVar('blogs', $bloger);

 $archive = Blogs::find(["order" => "datetime DESC"]);
    $this->view->setVar('archives',$archive);
}

[伏]

{% for archive in archives %}
<a href="blog/showfull/{{archive.id}}">{{ archive.datetime }}</a>
{% endfor %}

{% for bloger in blogs %}
{{bloger.bintro}}<br/>
{{bloger.bdesc}}<br/>
{{bloger.bconcl}}<br/>
{% endfor %}

档案呈现如下:     2016-04-16 12:30:05

但我想要

2016->
January->
date-1->time
date-2->time
February->
date-1->time
date-2->time
2015->
January->
date-1->time
date-2->time
February->
date-1->time
date-2->time

如何进行此查询以及如何以这种方式检索?请帮我一个轻量级的工作示例。

[伏]

我只是尝试这样但是如何分组呢?我指的是几个月以下的月份和日期,以及如何设置链接?

<?php
$year = date('Y',strtotime($archive->datetime));
$month = date('F',strtotime($archive->datetime));
$day = date('d',strtotime($archive->datetime));
$time = date('H:i:s',strtotime($archive->datetime));

echo('<ul><li>');
echo($year.'<ul><li>');
echo($month.'<ul><li>');
echo($day.' '.$time.'</li></ul></li></ul></li></ul>');
?>

1 个答案:

答案 0 :(得分:0)

您可以使用与在PHP中相同的方式格式化Volt中的日期。

{% for archive in archives %}
 <a href="blog/showfull/{{archive.id}}">{{ archive.datetime }}</a>

 Year: {{ date('Y', strtotime(archive.datetime)) }}
 Month: {{ date('F', strtotime(archive.datetime)) }}
 Time: {{ date('H:i:s', strtotime(archive.datetime)) }}
 ...

{% endfor %}

参考:https://docs.phalconphp.com/en/latest/reference/volt.html#functions