2016-07-13 3 views
0

나는 CakePHP 3.2에서 일하고 있습니다.CakePHP 3 :보기의 날짜 비교

timestamp의 날짜를 데이터베이스의 isThisMonth() CakePHP의 기능과 비교하고 싶습니다.

created의 날짜가 1 month 인 제품을 나열하고 있습니다. 제품과 함께 NEW 배지가 표시됩니다.

이 내가보기 여기

<?php $date = new DateTime($product->created); 
     $date = $date->format('Y-m-d'); 
     if ($date->isThisMonth()): ?> // error is pointing this line 
     <span class="new-product"> NEW</span> 
<?php endif; ?> 

$product에서 수행 한 것입니다 오류 항목이며 created는 데이터베이스에 타임 스탬프 열입니다.

그러나

Call to a member function isThisMonth() on string 

답변

1

시도가

$time = new Time($date); 

다음 http://book.cakephp.org/3.0/en/core-libraries/time.html#comparing-with-the-present

$time->isThisMonth()):

$date->isThisMonth()):를 교환 $date = $date->format('Y-m-d'); 아래이 추가로이 오류를 제공은포함in view.ctp.

+0

오류 '클래스'시간 '찾을 수 없습니다.' –

+0

해결 된 ..'view Cake \ I18n \ Time;'을 사용하여'view.ctp' 파일 –

+0

에 나를 이길 수 있습니다. – bill