Php 如何使用奏鸣曲碳库中的当前年份
我是索纳塔的新手,我正在尝试使用碳库生成今年所有记录的输出 这是来自碳库 碳::Iscurrent year 没有争论 返回布尔 检查实例是否与当前时刻处于同一年。 方法添加了1.22.0无参数 下面是我试图应用的代码Php 如何使用奏鸣曲碳库中的当前年份,php,sonata,Php,Sonata,我是索纳塔的新手,我正在尝试使用碳库生成今年所有记录的输出 这是来自碳库 碳::Iscurrent year 没有争论 返回布尔 检查实例是否与当前时刻处于同一年。 方法添加了1.22.0无参数 下面是我试图应用的代码 public function getIsActiveThisYear(): bool { $now = Carbon::isCurrentYear(); $endofyear = $endDate->year; $
public function getIsActiveThisYear(): bool
{
$now = Carbon::isCurrentYear();
$endofyear = $endDate->year;
$startofyear = $startDate->year;
return $this->$endofyear == $now || $this->$startofyear == $now;
}
此代码导致的错误为:
isCurrentYear does not exist
只要这样做:
$date = new DateTime(); // Carbon extends the PHP DateTime class so it's the same.
$thisYear = $date->format('Y');
检查文档!:-)
您还需要传递开始和结束日期
public function getIsActiveThisYear(DateTime $startDate, DateTime $endDate): bool
Carbon::isCurrentYear不是类的静态方法,它可以被称为
$date->isCurrentYear()
。顺便说一句,您的代码也没有意义$endDate和startDate是未查找的。