查询数据未显示在zf2的视图中? [英] Query data not show in view in zf2?
问题描述
我执行了一个索引操作,在该操作中,我使用了学说查询从日历表中选择数据,并且我想使用index.phtml显示数据,但是我的数据不只显示空白页,我如何从控制器显示数据以进行查看? 这是我的代码:
I make an index action in which i used doctrine query to select data from calendar table and i want to show data using index.phtml but my data not show only blank page shown,how i show data from controller to view? here is my code:
public function indexAction()
{
$dm = $this->getServiceLocator()->get('doctrine.documentmanager.odm_default');
$qb = $dm->createQueryBuilder('Calendar\Document\Calendar');
$query = $qb->getQuery();
$calendars = $query->execute();
return array('calendars' => $calenders)
}
这是我的index.phtml代码:
and here is my index.phtml code:
<?php
$calendars = $this->calendars;
$title = 'Calendars by';
$this->headTitle($title);
?>
<h3><?php echo $this->escapeHtml($title); ?></h3>
<ul>
<li><a href="<?php echo $this->url('calendar', array('action'=>'create'));?>">Create New Calendar</a></li>
</ul>
<h4>Calendars created by you</h4>
<?php if (is_null($calendars)): ?>
<p>No calendars</p>
<?php else: ?>
<table class="table">
<tr>
<th>calendar name</th>
<th>description</th>
<th>actions</th>
</tr>
<?php foreach ($calendars as $calendar) : ?>
<tr>
<td>
<a href="<?php echo $this->url('calendar',array('action'=>'show', 'id' => $calendar->calendar_id));?>">
<?php echo $this->escapeHtml($calendar->title);?>
</a>
</td>
<td><?php echo $this->escapeHtml($calendar->description);?></td>
<td>
<a href="<?php echo $this->url('calendar',
array('action'=>'settings', 'id' => $calendar->_id));?>">Settings</a>
<a href="<?php echo $this->url('calendar',
array('action'=>'delete', 'id' => $calendar->_id));?>">delete</a>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
这是我的回复:
Doctrine\ODM\MongoDB\Cursor Object
(
[baseCursor:Doctrine\ODM\MongoDB\Cursor:private] => Doctrine\MongoDB\Cursor Object
(
[connection:protected] => Doctrine\MongoDB\Connection Object
(
[mongo:protected] => MongoClient Object
(
[connected] => 1
[status] =>
[server:protected] =>
[persistent:protected] =>
)
我如何在index.phtml中显示查询结果?
how i show query result in index.phtml?
推荐答案
您需要将具有在关联数组中设置的属性的ViewModel返回给应用程序,否则将返回不带属性的默认ViewModel.
You need to return a ViewModel to the application with properties set in an associative array, otherwise a default ViewModel will be returned with no properties.
例如:
return new ViewModel(array(
'content' => 'foo bar!'
));
然后在您的.phtml文件中:
Then in your .phtml file:
<p><?php print $this->content; ?></p>
这篇关于查询数据未显示在zf2的视图中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!