没有提供paginator实例或者zend中的类型不正确?

时间:2012-04-12 07:16:14

标签: zend-framework

我正在尝试使用zend在jquery移动框架中实现分页。我有以下代码来自控制器,

...
        $message_list = $this->help->browse($browseArray); 
        $this->view->vCount = count($message_list); 
        $paginator = Zend_Paginator::factory($message_list);
        $page = ($postData['page'] > 0) ? $postData['page'] : 1;
        $paginator->setCurrentPageNumber($page);
        $paginator->setItemCountPerPage(10);
        $paginator->setPageRange(5);

        $this->view->message_list = $paginator;   
....

我还从模板页面

获取了以下代码
....
    <ul data-role="listview"  data-theme="e">
        <?php foreach ($this->message_list as $key => $value) { ?>
            <li>
                <img src="<?php echo BASE_URL; ?>public/common/images/mobile/jqueryMobile200Thumb.jpg" alt="" />
                <h3><a href="<?php echo $this->url(array("controller" => "help", "action" => "dohelp", "id" => $value['helpid'])); ?>"><?php echo $value['title']; ?></a></h3>
                <p><?php echo $value['content']; ?></p>
            </li>
        <?php } ?>    
            <li>
                <?php echo $this->paginationControl($this->message_list, 'Sliding', 'pagination.phtml'); ?>
            </li>           
    </ul>
....

当我运行该网站时,我得到以下异常

        Exception information:

        Message: No paginator instance provided or incorrect type
        Stack trace:

        #0 [internal function]: Zend_View_Helper_PaginationControl->paginationControl(NULL, 'Sliding', 'pagination.phtm...')
#1 C:\xampp\htdocs\test\library\Zend\View\Abstract.php(350): call_user_func_array(Array, Array)
#2 C:\xampp\htdocs\test\application\mobile\views\scripts\help\messagelist.phtml(32): Zend_View_Abstract->__call('paginationContr...', Array)
#3 C:\xampp\htdocs\test\application\mobile\views\scripts\help\messagelist.phtml(32): Zend_View->paginationControl(NULL, 'Sliding', 'pagination.phtm...')
#4 C:\xampp\htdocs\test\library\Zend\View.php(108): include('C:\xampp\htdocs...')
#5 C:\xampp\htdocs\test\library\Zend\View\Abstract.php(888): Zend_View->_run('C:\xampp\htdocs...')
#6 C:\xampp\htdocs\test\library\ZC\Controller\Plugin\Mobile.php(54): Zend_View_Abstract->render('help/messagelis...')
#7 C:\xampp\htdocs\test\library\Zend\Controller\Plugin\Broker.php(287): ZC_Controller_Plugin_Mobile->dispatchLoopStartup(Object(Zend_Controller_Request_Http))
#8 C:\xampp\htdocs\test\library\Zend\Controller\Front.php(928): Zend_Controller_Plugin_Broker->dispatchLoopStartup(Object(Zend_Controller_Request_Http))
#9 C:\xampp\htdocs\test\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#10 C:\xampp\htdocs\test\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#11 C:\xampp\htdocs\test\index.php(34): Zend_Application->run()
#12 {main}  
    ....

我在这方面做错了什么。请帮助我。

2 个答案:

答案 0 :(得分:1)

尝试这种方式:

$paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Array($message_list));

要回答您的问题,系统会显示错误,因为$this->message_list null尝试调试原因null

答案 1 :(得分:0)

检查您是否正确设置了视图对象中的$paginator变量。我有这种情况,发现我没有正确这样做。

相关问题