Magento에서 Mage_Core_Model_Abstract에서 상속받은 사용자 정의 모델 모음을 반복하는 phtml이 있습니다. 이 모델에는 '날짜'라는 DB 필드가 있습니다.Magento에서 MySQL의 날짜가 잘못 표시됨
phtml은 반복되는 각 항목의 브라우저에 getDate() 함수의 출력을 표시 할 때 대부분 정확한 시간을 표시합니다. 불명확 한 날짜 (M/d/Y 또는 d/M/Y로 해석 될 수있는 날짜)는 잘못되었습니다 .MySQL 테이블에서 날짜 필드 (datetime)를 확인하고 모든 날짜가 올바르게 저장됩니다. 는 DB에서 그것을 읽고 한 번 잘못된 날짜를 interpretting 예를 들어
:. 나는 구글이 검색 및 StackOverflow에보고했던,하지만 난이 문제를 해결하는 방법을 잘 모르겠어요
In MySQL => HTML Output => status
2013-12-05 00:00:00 => 5/12/2013 => Wrong
2013-11-30 00:00:00 => 11/30/2013 => Correct
2013-11-06 00:00:00 => 6/11/2013 => Wrong
2013-10-11 00:00:00 => 11/10/2013 => Wrong
etc.
. 어떤 아이디어 감사
업데이트 :?. 가 나는 전자이었다 쿼리를 얻을 수있는 컬렉션 (참) printLogQuery를 사용 실행. 그것은 간단했다 : SELECT main_table
. * FROM physicians_event
main_table
;
public function getEventCollection() {
if ($this->getSortBy() === null) {
$this->setSortBy('date');
}
if ($this->getLimit() === null) {
$this->setLimit(10);
}
$collection = Mage::getModel('physicians/event')->getCollection();
$collection->setOrder($this->getSortBy())
->setPageSize($this->getLimit());
if ($this->getEventType() !== null) {
$collection->addFieldToFilter('type', array('eq' => $this->getEventType()));
}
return $collection;
}
:
<?php foreach ($this->getEventCollection() as $_event): ?>
<?php echo $this->getLayout()->createBlock('physicians/event')
->setEvent($_event)
->setTemplate('physicians/event/row.phtml')
->toHtml() ?>
<?php endforeach ?>
getEventCollection은 다음과 같습니다
모든 것이 HTML (컬렉션의 각 항목에 대해 렌더링되는 row.phtml)로 출력되면 날짜는 다음과 같이 출력됩니다.
<?php echo $this->getEvent()->getFormattedDate('M/d/Y') ?>
getFormattedDate 기능은 다음과 같습니다 :
public function getFormattedDate($format = null, $puredate=false) {
$date = new Zend_Date($this->getDate());
if ($format === null) {
$format = 'MMMM d, Y';
}
return (!$puredate)?$date->toString($format):$date;
}
내가 그 지금까지 전체 기사 믿습니다. 아이디어? 다시 한 번 감사드립니다.
업데이트 : 추가 디버깅.
echo "Collection Item Date: " . var_export($this->getDate()) . "<br/>\n";
$date = new Zend_Date($this->getDate());
echo "Zend Item Date: " . var_export($date,true) . "<br/>\n";
출력이처럼 보였다 :
Collection Item Date: '2013-07-06 00:00:00'
Zend Item Date: Zend_Date::__set_state(array(
'_locale' => 'en_US',
'_fractional' => 0,
'_precision' => 3,
'_unixTimestamp' => '1370563200',
'_timezone' => 'UTC',
'_offset' => 0,
'_syncronised' => 0,
'_dst' => false,
))
두 항목이 제대로 2013년 7월 6일있는 데이터가 잘못 곳 getFormattedDate의 내부, 나는 추적 출력 문을 추가했다. 나는 나중에 코드에서 엉망이되고 있다고 생각한다.
echo "<pre>" . var_export($date->toString($format),true) . "</pre><br />\n";
그리고 그의 출력했다 : 잘못된 '2013년 6월 7일을'추적은
내가이 추가 ... 계속한다. 그래서 문제는내가 지금 꺼져있는 것을 보려면 여기를 통해거야 ... $ 날짜 -이> toString ($ 형식)의 작동 방식에 있습니다 http://framework.zend.com/manual/1.12/en/zend.date.constants.html#zend.date.constants.selfdefinedformats
귀하의 질문에 답하십시오! –
Zend/Mage 시스템을 통해 모든 것이 검색되므로 정확한 쿼리를 실제로 알지 못합니다. Zend_DB_Table_Abstract 또는 Magento에서 사용하는 모델을 상속 한 모델을 만든 다음 해당 모델의 객체에서 get()을 파생 시키면 자동으로 SQL을 생성하고 DB를 쿼리하여 PHP 객체를 만듭니다. – Morfie
데이터베이스를 만들 때 사용한 데이터 정렬은 무엇입니까? 'utf8_unicode_ci'를 사용하십시오. –