我正在使用phalcon-2.1.0。我只是为我的博客存档创建一个日历。我想从数据库中检索与日期匹配的数据。我的代码只检索一个帖子,这是我在db中的最后一篇文章。我不了解如何查询循环以检查日期相关数据。我需要检索与用户点击日期相关的帖子。
[控制器]
Offset Size Description
~ ~ Standard Attribute Header
0x00 8 File reference to the parent directory.
0x08 8 C Time - File Creation
0x10 8 A Time - File Altered
0x18 8 M Time - MFT Changed
0x20 8 R Time - File Read
0x28 8 Allocated size of the file
0x30 8 Real size of the file
0x38 4 Flags, e.g. Directory, compressed, hidden
0x3c 4 Used by EAs and Reparse
0x40 1 Filename length in characters (L)
0x41 1 Filename namespace
0x42 2L File name in Unicode (not null terminated)
[博客页面中的日历]
# Define the root logger with appender file
log4j.rootLogger = DEBUG, FILE
# Define the file appender
log4j.appender.FILE=org.apache.log4j.RollingFileAppender
# Set the name of the file
log4j.appender.FILE.File=D:/AppLog/one.log
# Set the immediate flush to true (default)
log4j.appender.FILE.ImmediateFlush=true
# Set the threshold to debug mode
log4j.appender.FILE.Threshold=debug
# Set the append to false, should not overwrite
log4j.appender.FILE.Append=true
# Set the maximum file size before rollover
log4j.appender.FILE.MaxFileSize=100KB
# Set the the backup index
log4j.appender.FILE.MaxBackupIndex=1000
# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss} %m%n
[查看 - 存档.volt]
public function indexAction()
{
$bloger = Blogs::find();
$postedDays = [];
foreach ($bloger as $blog) {
$date = date('Y-m-d', strtotime($blog->datetime));
if (!in_array($date, $postedDays)) {
$postedDays[] = $date;
}
}
$this->view->setvar('dates', $postedDays);
}
public function archivesAction($date)
{
$archs = Blogs::find(["datetime LIKE :key:","bind"=>["key"=>'%'.$date.'%']]);
$this->view->setvar('dates', $archs);
$this->view->pick('blog/archive');
}
答案 0 :(得分:0)
您的archivesAction
会使用您未使用的参数$date
。
您基本上是在查询所有博客并循环浏览它们。在循环时,您可以为$times
,$dater
和$timer
分配值。在foreach
结束后,这些值将包含您上次博客记录的日期。
$get = Blogs::find();
foreach($get as $d)
{
$times = explode(' ', $d->datetime);
$dater = $times[0];
$timer = $times[1];
}
$archs = Blogs::find(["datetime LIKE :key:","bind"=>["key"=>'%'.$dater.'%']]);
您应该做的是从您的操作archivesAction($date)
的参数中获取日期。用这一行替换上面的代码行:
// changed variable $dater to $date
$archs = Blogs::find(["datetime LIKE :key:", "bind" => ["key"=> '%' . $date . '%']]);
更新
要让您的月份始终输出2个字符,您可以执行此操作:
<?php prev_month = str_pad($prev_month, 2, '0', STR_PAD_LEFT); ?>
<a href="blog?month=<?php echo($prev_month.'&year='.$prev_year);?>">‹</a>
检查str_pad documentation以获取更多相关信息。
更新2
要仅突出显示数据库中包含帖子的日历日,您可以执行以下操作:
[控制器]
$blogs = Blogs::find();
$uniqueDays = [];
foreach ($blogs as $blog) {
$date = date('Y-m-d', strtotime($blog->datetime));
if (!in_array($date, $uniqueDays)) {
$uniqueDays[] = $date;
}
}
$this->view->setVar('databaseDates', $uniqueDays');
[图]
<?php
if (in_array($year.'-'.$month.'-'.$startdate, $databaseDates) {
// date is found in the database
// highlight date
}