dqwcdqs358367 2010-02-01 11:26
浏览 32
已采纳

带有Zend_Paginator对象问题的PartialLoop

Is it possible to use the findParentRow() method from within a Zend_Paginator Object? I'm trying some code that works fine on an object returned by fetchAll from a DB resultset and works fine. With the Zend_Paginator object it doesnt work though.

In my controller i have:

public function downloadedAction()
{
    $images = new Model_ApplicationImages();
    $paginator = $images->fetchPaginated();
    $paginator->setCurrentPageNumber($this->_getParam('page'));
    $this->view->paginator = $paginator;
}

In my model i have:

public function fetchPaginated()
{
    $select = $this->select()
                   ->from($this->_name)
                   ->where('status = ?','approved')
                   ->where('downloaded = ?','0');
    $adapter = new Zend_Paginator_Adapter_DbSelect($select);
    $paginator = new Zend_Paginator($adapter);
    $paginator->setItemCountPerPage(10);
    return $paginator;
}

In my view i have:

    $this->partialLoop()->setObjectKey('paginator');
    echo $this->partialLoop('admin/list-downloaded.phtml', $this->paginator); 

and in the partial:

    $this->paginator->findParentRow('Model_Application')->name

It appears though that the object key is not being used or not being set properly as within the partial var_dump($this->paginator) is NULL and the other values being passed from the paginator are there but under $this->key and not $this->paginator->key as they should be

  • 写回答

3条回答 默认 最新

  • dttphb59319 2010-02-08 20:56
    关注

    A PartialLoop essentially runs a Partial for each element in the array or Traversable object passed to it. So by the time it gets to your partial view script, you're no longer working with the Paginator object, but with its paginated contents.

    In a partial loop, the setObjectKey() works at the partial level. You can pass an array of Traversable objects (or a Traversable object that iterates over Traversable objects) to a partial loop and in the partial each object will then be accessible through the object key.

    The DbSelect paginator adapter you're using, however, returns an array of rows for each page, so there isn't any object to be put in the paginator object key and it remains unused.

    You should use the DbTableSelect adapter instead, which will return a rowset.

    If you need access to the Paginator itself you should use a partial instead. That way you can use setObjectKey() to loop over the pages in the paginator yourself.

    I suggest you keep the source code of the Zend Framework handy when something doesn't work the way you expect. Sadly, I've had more success figuring out how to use it by reading through the code than by reading through the documentation.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题