dongshou6788 2014-04-16 22:29
浏览 22
已采纳

查询数据在zf2中不显示在视图中? [重复]

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)
    }

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; ?>

and here is my response:

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] => 
                        )

                [server:protected] => mongodb://127.0.0.1:27017/events
                [options:protected] => Array
                    (
                    )

                [config:protected] => Doctrine\ODM\MongoDB\Configuration Object
                    (
                        [attributes:protected] => Array
                            (
                                [mongoCmd] => $
                                [retryConnect] => 0
                                [retryQuery] => 0
                                [autoGenerateProxyClasses] => 1
                                [proxyDir] => data/DoctrineMongoODMModule/Proxy
                                [proxyNamespace] => DoctrineMongoODMModule\Proxy
                                [autoGenerateHydratorClasses] => 1
                                [hydratorDir] => data/DoctrineMongoODMModule/Hydrator
                                [hydratorNamespace] => DoctrineMongoODMModule\Hydrator
                                [defaultDB] => events
                                [metadataCacheImpl] => Doctrine\Common\Cache\ArrayCache Object
                                    (
                                        [data:Doctrine\Common\Cache\ArrayCache:private] => Array ...................................

how i show query result in index.phtml?

</div>

展开全部

  • 写回答

1条回答 默认 最新

  • dtrt2368 2014-04-16 23:05
    关注

    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.

    Eg:

    return new ViewModel(array(
        'content' => 'foo bar!'
    ));
    

    Then in your .phtml file:

    <p><?php print $this->content; ?></p>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 Mysql 一张表同时多人查询和插入怎么防止死锁
  • ¥20 centos6.7 安装libevent库.总是报错,如何解决?
  • ¥15 电脑买回,学校的有线网络总掉。
  • ¥20 关于普洛菲斯触摸屏与AB连接地址问题
  • ¥15 vue但是页面显示的数据为空为什么呀,明明在钩子函数中已经成功赋值(相关搜索:输出数据)
  • ¥15 syri可视化不显示插入缺失
  • ¥30 运行软件卡死查看系统日志分析不出来
  • ¥15 C语言代码改正特征选择算法设计,贝叶斯决策,,设计分类器,远程操作代码修正一下
  • ¥15 String 类valuve指向的问题
  • ¥15 在ros2的iron版本进行编译时遇到如下问题
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部