I`m having trouble with extracting data with DataTime type from the database with ORM Doctrine in Zend Framework.
This problem occurs, because I can`t really understand how to work with this type of data.. Can you help me to fix that?
I need to show news date. I tried: $item->getDate()
, but page shows
"Error 500".
After var_dump($item->getDate()); I get this:
<?php
foreach ($articles as $item) {
$category = $item->getCategory();
$edit = $this->Url('admin/add-edit-delete', array('action'=>'action', 'subAction'=>'edit', 'element' => 'news', 'newsTitle' => str_replace(" ","-",$item->getTitle()), 'id'=>$item->getId()),null,true);
$delete = $this->Url('admin/add-edit-delete', array('action'=>'action', 'subAction'=>'delete', 'element' => 'news', 'id'=>$item->getId()),null,true);
$show_article = $this->Url('news/article', array('action' => 'article', 'title' => str_replace(' ', '-', str_replace('!', '', $item->getTitle())), 'id' => $item->getId()),null,true);
$count_comment = "<span class='badge' style='float: right' data-toggle=\"tooltip\" data-placement=\"left\" title=\"Количество комментариев\">{$item->getComments()->count()}</span>";
$title = ($item->getComments()->count() != 0)?'Открыть список комментариев к статье':null;
if ($category) {
$categoryKey = $category->getCategoryKey();
} else {
$categoryKey = 'категория не указана';
}
if ($item->getIsPublic()) {
$isPublic = 'да';
} else {
$isPublic = 'нет';
}
echo "
<tr>
<td>{$item->getId()}</td>
<td>{$categoryKey}</td>
<td><p data-toggle=\"tooltip\" data-placement=\"right\" title=\"{$title}\"><a href='' data-toggle='modal' data-target='#myModal-comments-{$item->getId()}'>{$item->getTitle()}</a>{$count_comment}</p></td>
<td></td>
";
echo "
<td>{$isPublic}</td>
<td style=\"text-align: right; width: 76px\">
";
echo '
<a href="'.$edit.'" data-toggle="tooltip" data-placement="left" title="Редактировать"><span class="glyphicon glyphicon-edit" style="color: #808080"></span></a>
<a href="'.$delete.'" data-toggle="tooltip" data-placement="left" title="Удалить"><span class="glyphicon glyphicon-trash" style="color: #808080"></span></a>
';
echo "
</td>
</tr>
";
}
?>
Thanks to @Cerad, here is a solution of a problem:
echo ($item->getDate() != null) ? $item->getDate()->format('d.m.Y') : "Дата не указана";