Zend 分页与数组

发布于 2024-08-09 06:24:23 字数 9859 浏览 7 评论 0原文

我目前正在使用 ezSQL,我相信它是一个很棒的 SQL 包装器。我的任务是添加我们可以直接插入的分页。Zend 有one,这似乎应该可以工作,因为它与 Zend 的其余部分松散耦合。我使用 ezSQL, ala: 返回一个数组,

$results = $db->get_results("SELECT * FROM table", ARRAY_A);

然后将其转移到分页器:

$paginator = Zend_Paginator::factory($results);

如果我 var_dump($paginator),我会看到查询中列出的值。但是,如果我echo $paginator->pageCount),我会得到NULL。这是怎么回事?

不幸的是,从 ezSQL 切换到 Zend_DB 对于我们组来说基本上是不可能的,所以这是不可能的。

编辑print_r($paginator)的输出:

Zend_Paginator Object
(
    [_cacheEnabled:protected] => 1
    [_adapter:protected] => Zend_Paginator_Adapter_Array Object
        (
            [_array:protected] => Array
                (
                    [0] => Array
                        (
                            [first_name] => Doug
                            [last_name] => Lawrence
                            [avatar] => Doug_Lawrence.png
                            [updated_by] => 14306
                            [id] => 413
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-29 12:57:52
                            [publish_date] => 10/29/09
                        )

                    [1] => Array
                        (
                            [first_name] => Jason
                            [last_name] => Lewis
                            [avatar] => Jason.Lewis.jpg
                            [updated_by] => 13547
                            [id] => 411
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-25 09:19:48
                            [publish_date] => 10/25/09
                        )

                    [2] => Array
                        (
                            [first_name] => David
                            [last_name] => Bowman
                            [avatar] => David_Bowman.png
                            [updated_by] => 13564
                            [id] => 409
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-24 15:13:13
                            [publish_date] => 10/24/09
                        )

                    [3] => Array
                        (
                            [first_name] => David
                            [last_name] => Bowman
                            [avatar] => David_Bowman.png
                            [updated_by] => 13564
                            [id] => 410
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-24 15:15:48
                            [publish_date] => 10/24/09
                        )

                    [4] => Array
                        (
                            [first_name] => Greg
                            [last_name] => Morris
                            [avatar] => GKMorris.png
                            [updated_by] => 13555
                            [id] => 408
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-24 10:21:14
                            [publish_date] => 10/24/09
                        )

                    [5] => Array
                        (
                            [first_name] => Thom
                            [last_name] => Rainer
                            [avatar] => Thom_Rainer.jpg
                            [updated_by] => 13560
                            [id] => 405
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-23 06:53:43
                            [publish_date] => 10/23/09
                        )

                    [6] => Array
                        (
                            [first_name] => David
                            [last_name] => Bowman
                            [avatar] => David_Bowman.png
                            [updated_by] => 13564
                            [id] => 406
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-23 16:20:33
                            [publish_date] => 10/23/09
                        )

                    [7] => Array
                        (
                            [first_name] => Tom
                            [last_name] => Harper
                            [avatar] => 1225910432_63
                            [updated_by] => 10843
                            [id] => 402
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-22 11:17:16
                            [publish_date] => 10/22/09
                        )

                    [8] => Array
                        (
                            [first_name] => Jerome
                            [last_name] => Daley
                            [avatar] => Jerome_Daley.png
                            [updated_by] => 13554
                            [id] => 403
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-22 14:06:31
                            [publish_date] => 10/22/09
                        )

                    [9] => Array
                        (
                            [first_name] => Mark
                            [last_name] => Howell
                            [avatar] => Mark_Best.png
                            [updated_by] => 13561
                            [id] => 404
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-22 21:44:51
                            [publish_date] => 10/22/09
                        )

                    [10] => Array
                        (
                            [first_name] => Margaret
                            [last_name] => Marcuson
                            [avatar] => Marcuson.png
                            [updated_by] => 14398
                            [id] => 401
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-21 18:21:55
                            [publish_date] => 10/21/09
                        )

                    [11] => Array
                        (
                            [first_name] => Barry
                            [last_name] => Winders
                            [avatar] => Barry_Winders.png
                            [updated_by] => 13552
                            [id] => 400
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-20 20:08:36
                            [publish_date] => 10/20/09
                        )

                    [12] => Array
                        (
                            [first_name] => Stephen
                            [last_name] => Gray
                            [avatar] => Stephen_Gray.png
                            [updated_by] => 13556
                            [id] => 399
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-20 09:59:16
                            [publish_date] => 10/20/09
                        )

                    [13] => Array
                        (
                            [first_name] => Alan
                            [last_name] => Chandler
                            [avatar] => Alan_Chandler.png
                            [updated_by] => 13549
                            [id] => 398
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-19 12:03:07
                            [publish_date] => 10/19/09
                        )

                    [14] => Array
                        (
                            [first_name] => Mark
                            [last_name] => Howell
                            [avatar] => Mark_Best.png
                            [updated_by] => 13561
                            [id] => 396
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-17 12:30:16
                            [publish_date] => 10/17/09
                        )

                )

            [_count:protected] => 15
        )

    [_currentItemCount:protected] => 
    [_currentItems:protected] => 
    [_currentPageNumber:protected] => 1
    [_filter:protected] => 
    [_itemCountPerPage:protected] => 5
    [_pageCount:protected] => 3
    [_pageRange:protected] => 10
    [_pages:protected] => 
    [_view:protected] => 
)

I'm currently using ezSQL, which I believe to be a great SQL wrapper. I've been tasked with adding in pagination that we can just drop in. Zend has one, which seems like it should work, as it's loosely coupled with the rest of Zend. I'm returning an array with ezSQL, ala:

$results = $db->get_results("SELECT * FROM table", ARRAY_A);

and then shifting this in to the paginator:

$paginator = Zend_Paginator::factory($results);

If I var_dump($paginator), I see the values listed from the query. However, if I echo $paginator->pageCount), I get NULL. What's the deal?

Unfortunately, switching from ezSQL to Zend_DB is essentially impossible for our group, so that's out of the question.

EDIT: Output from print_r($paginator):

Zend_Paginator Object
(
    [_cacheEnabled:protected] => 1
    [_adapter:protected] => Zend_Paginator_Adapter_Array Object
        (
            [_array:protected] => Array
                (
                    [0] => Array
                        (
                            [first_name] => Doug
                            [last_name] => Lawrence
                            [avatar] => Doug_Lawrence.png
                            [updated_by] => 14306
                            [id] => 413
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-29 12:57:52
                            [publish_date] => 10/29/09
                        )

                    [1] => Array
                        (
                            [first_name] => Jason
                            [last_name] => Lewis
                            [avatar] => Jason.Lewis.jpg
                            [updated_by] => 13547
                            [id] => 411
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-25 09:19:48
                            [publish_date] => 10/25/09
                        )

                    [2] => Array
                        (
                            [first_name] => David
                            [last_name] => Bowman
                            [avatar] => David_Bowman.png
                            [updated_by] => 13564
                            [id] => 409
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-24 15:13:13
                            [publish_date] => 10/24/09
                        )

                    [3] => Array
                        (
                            [first_name] => David
                            [last_name] => Bowman
                            [avatar] => David_Bowman.png
                            [updated_by] => 13564
                            [id] => 410
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-24 15:15:48
                            [publish_date] => 10/24/09
                        )

                    [4] => Array
                        (
                            [first_name] => Greg
                            [last_name] => Morris
                            [avatar] => GKMorris.png
                            [updated_by] => 13555
                            [id] => 408
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-24 10:21:14
                            [publish_date] => 10/24/09
                        )

                    [5] => Array
                        (
                            [first_name] => Thom
                            [last_name] => Rainer
                            [avatar] => Thom_Rainer.jpg
                            [updated_by] => 13560
                            [id] => 405
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-23 06:53:43
                            [publish_date] => 10/23/09
                        )

                    [6] => Array
                        (
                            [first_name] => David
                            [last_name] => Bowman
                            [avatar] => David_Bowman.png
                            [updated_by] => 13564
                            [id] => 406
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-23 16:20:33
                            [publish_date] => 10/23/09
                        )

                    [7] => Array
                        (
                            [first_name] => Tom
                            [last_name] => Harper
                            [avatar] => 1225910432_63
                            [updated_by] => 10843
                            [id] => 402
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-22 11:17:16
                            [publish_date] => 10/22/09
                        )

                    [8] => Array
                        (
                            [first_name] => Jerome
                            [last_name] => Daley
                            [avatar] => Jerome_Daley.png
                            [updated_by] => 13554
                            [id] => 403
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-22 14:06:31
                            [publish_date] => 10/22/09
                        )

                    [9] => Array
                        (
                            [first_name] => Mark
                            [last_name] => Howell
                            [avatar] => Mark_Best.png
                            [updated_by] => 13561
                            [id] => 404
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-22 21:44:51
                            [publish_date] => 10/22/09
                        )

                    [10] => Array
                        (
                            [first_name] => Margaret
                            [last_name] => Marcuson
                            [avatar] => Marcuson.png
                            [updated_by] => 14398
                            [id] => 401
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-21 18:21:55
                            [publish_date] => 10/21/09
                        )

                    [11] => Array
                        (
                            [first_name] => Barry
                            [last_name] => Winders
                            [avatar] => Barry_Winders.png
                            [updated_by] => 13552
                            [id] => 400
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-20 20:08:36
                            [publish_date] => 10/20/09
                        )

                    [12] => Array
                        (
                            [first_name] => Stephen
                            [last_name] => Gray
                            [avatar] => Stephen_Gray.png
                            [updated_by] => 13556
                            [id] => 399
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-20 09:59:16
                            [publish_date] => 10/20/09
                        )

                    [13] => Array
                        (
                            [first_name] => Alan
                            [last_name] => Chandler
                            [avatar] => Alan_Chandler.png
                            [updated_by] => 13549
                            [id] => 398
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-19 12:03:07
                            [publish_date] => 10/19/09
                        )

                    [14] => Array
                        (
                            [first_name] => Mark
                            [last_name] => Howell
                            [avatar] => Mark_Best.png
                            [updated_by] => 13561
                            [id] => 396
                            [title] => 
                            [synopsis] => 
                            [create_date] => 2009-10-17 12:30:16
                            [publish_date] => 10/17/09
                        )

                )

            [_count:protected] => 15
        )

    [_currentItemCount:protected] => 
    [_currentItems:protected] => 
    [_currentPageNumber:protected] => 1
    [_filter:protected] => 
    [_itemCountPerPage:protected] => 5
    [_pageCount:protected] => 3
    [_pageRange:protected] => 10
    [_pages:protected] => 
    [_view:protected] => 
)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请别遗忘我 2024-08-16 06:24:23

正如 Zak 所写,您缺少

$paginator->setItemCountPerPage(10);
$paginator->setCurrentPageNumber(1);

可以创建一个视图脚本来呈现分页器控件和分页器中的项目的功能。

则必须调用。

$paginator->getPages()->pageCount

如果您不使用 Zend_View 及其 paginatorControl 视图助手,

As Zak wrote, you are missing

$paginator->setItemCountPerPage(10);
$paginator->setCurrentPageNumber(1);

that you can create a view script to render the paginator controls and the items in the paginator.

Than you have to call

$paginator->getPages()->pageCount

if you are not using Zend_View and it's paginatorControl view helper.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文