cakephp每月显示条目

cakephp每月显示条目,php,cakephp,Php,Cakephp,我有以下脚本,其中显示了5张最近的发票,如下所示: <?php $year = (int)(substr($invoice['Invoice']['invoice_date'], 0, -6)); $month = (int)(substr($invoice['Invoice']['invoice_date'], 5, -3)); ?> <?php if($count < 5) : ?> 现在显示5张最新的发票,无论它们是哪个月到期的。如何调整/更改

我有以下脚本,其中显示了5张最近的发票,如下所示:

<?php 
  $year = (int)(substr($invoice['Invoice']['invoice_date'], 0, -6));
  $month = (int)(substr($invoice['Invoice']['invoice_date'], 5, -3));
?>
<?php if($count < 5) : ?>


现在显示5张最新的发票,无论它们是哪个月到期的。如何调整/更改此代码片段以向我展示当月的5张发票?

为什么不使用
cakephp time helper

<?php $year  = $time->format('Y',$invoice['Invoice']['invoice_date']); ?>
<?php $month = $time->format('m',$invoice['Invoice']['invoice_date']); ?>

要获得本月的最新记录,请尝试以下解决方案

<?php

$this->Invoice->find('all', array
(
    'conditions'=> array('DATE_FORMAT(Invoice.invoice_date,"%m") = "'.date("m").'"')
));

$time->
应该是
$this->time->
!嗯,但是当我们可以在视图文件中访问它时,我认为我们不需要$this..因为我尝试了不使用$this,并且它工作了..对于所有cake版本>=1.3,这仍然是我刚才所说的。在此之前,它是旧语法。即使它可能会工作,但它已被弃用,并且可以并且将停止使用升级。因此,我认为写过时的、可能错误的答案毫无意义。thanx作为参考标记..非常感谢…今天就学习一些新的东西。