对zend对象进行排序


Sorting zend object

当我打印_r($this->paginator)时;我得到:

> Zend_Paginator Object ( [_cacheEnabled:protected] => 1
> [_adapter:protected] => Zend_Paginator_Adapter_DbSelect Object (
> [_countSelect:protected] => Zend_Db_Select Object ( [_bind:protected]
> => Array ( ) [_adapter:protected] => Zend_Db_Adapter_Pdo_Mysql Object ( [_pdoType:protected] => mysql [_numericDataTypes:protected] => Array
> ( [0] => 0 [1] => 1 [2] => 2 [INT] => 0 [INTEGER] => 0 [MEDIUMINT] =>
> 0 [SMALLINT] => 0 [TINYINT] => 0 [BIGINT] => 1 [SERIAL] => 1 [DEC] =>
> 2 [DECIMAL] => 2 [DOUBLE] => 2 [DOUBLE PRECISION] => 2 [FIXED] => 2
> [FLOAT] => 2 ) [_defaultStmtClass:protected] => Zend_Db_Statement_Pdo
> [_config:protected] => Array ( [host] => localhost [username] =>
> zagadkikinowe [password] => rdh2jhyTs [dbname] => zagadkikinowe
> [charset] => utf8 [persistent] => [options] => Array ( [caseFolding]
> => 0 [autoQuoteIdentifiers] => 1 ) [driver_options] => Array ( [1002] => SET NAMES 'utf8' ) ) [_fetchMode:protected] => 2 [_profiler:protected] => Zend_Db_Profiler Object (
> [_queryProfiles:protected] => Array ( ) [_enabled:protected] =>
> [_filterElapsedSecs:protected] => [_filterTypes:protected] => )
> [_defaultProfilerClass:protected] => Zend_Db_Profiler
> [_connection:protected] => PDO Object ( ) [_caseFolding:protected] =>
> 0 [_autoQuoteIdentifiers:protected] => 1
> [_allowSerialization:protected] => 1
> [_autoReconnectOnUnserialize:protected] => ) [_parts:protected] =>
> Array ( [distinct] => [columns] => Array ( [0] => Array ( [0] =>
> user_answer [1] => Zend_Db_Expr Object ( [_expression:protected] =>
> COUNT(1) AS `zend_paginator_row_count` ) [2] => ) ) [union] => Array (
> ) [from] => Array ( [user_answer] => Array ( [joinType] => from
> [schema] => [tableName] => user_answer [joinCondition] => ) ) [where]
> => Array ( [0] => (edition_id='22') [1] => AND (answer_type = "close") ) [group] => Array ( ) [having] => Array ( ) [order] => Array ( )
> [limitcount] => [limitoffset] => [forupdate] => )
> [_tableCols:protected] => Array ( ) ) [_select:protected] =>
> Zend_Db_Select Object ( [_bind:protected] => Array ( )
> [_adapter:protected] => Zend_Db_Adapter_Pdo_Mysql Object (
> [_pdoType:protected] => mysql [_numericDataTypes:protected] => Array (
> [0] => 0 [1] => 1 [2] => 2 [INT] => 0 [INTEGER] => 0 [MEDIUMINT] => 0
> [SMALLINT] => 0 [TINYINT] => 0 [BIGINT] => 1 [SERIAL] => 1 [DEC] => 2
> [DECIMAL] => 2 [DOUBLE] => 2 [DOUBLE PRECISION] => 2 [FIXED] => 2
> [FLOAT] => 2 ) [_defaultStmtClass:protected] => Zend_Db_Statement_Pdo
> [_config:protected] => Array ( [host] => localhost [username] =>
> zagadkikinowe [password] => rdh2jhyTs [dbname] => zagadkikinowe
> [charset] => utf8 [persistent] => [options] => Array ( [caseFolding]
> => 0 [autoQuoteIdentifiers] => 1 ) [driver_options] => Array ( [1002] => SET NAMES 'utf8' ) ) [_fetchMode:protected] => 2 [_profiler:protected] => Zend_Db_Profiler Object (
> [_queryProfiles:protected] => Array ( ) [_enabled:protected] =>
> [_filterElapsedSecs:protected] => [_filterTypes:protected] => )
> [_defaultProfilerClass:protected] => Zend_Db_Profiler
> [_connection:protected] => PDO Object ( ) [_caseFolding:protected] =>
> 0 [_autoQuoteIdentifiers:protected] => 1
> [_allowSerialization:protected] => 1
> [_autoReconnectOnUnserialize:protected] => ) [_parts:protected] =>
> Array ( [distinct] => [columns] => Array ( [0] => Array ( [0] =>
> user_answer [1] => * [2] => ) ) [union] => Array ( ) [from] => Array (
> [user_answer] => Array ( [joinType] => from [schema] => [tableName] =>
> user_answer [joinCondition] => ) ) [where] => Array ( [0] =>
> (edition_id='22') [1] => AND (answer_type = "close") ) [group] =>
> Array ( ) [having] => Array ( ) [order] => Array ( [0] => Array ( [0]
> => time [1] => ASC ) ) [limitcount] => 25 [limitoffset] => 0 [forupdate] => ) [_tableCols:protected] => Array ( ) )
> [_rowCount:protected] => 6 ) [_currentItemCount:protected] => 6
> [_currentItems:protected] => ArrayIterator Object ( [0] => Array (
> [id] => 9611 [edition_id] => 22 [uid] => 1429046328 [city_id] => 41
> [time] => 1346330264 [answer] => [answer_type] => close [winner] => 0
> [canwin] => 1 [name] => xxx ) [1] => Array ( [id] => 9613
> [edition_id] => 22 [uid] => 100002892496926 [city_id] => 41 [time] =>
> 1346330506 [answer] => [answer_type] => close [winner] => 0 [canwin]
> => 1 [name] => xxx ) [2] => Array ( [id] => 9618 [edition_id] => 22 [uid] => 1321291427 [city_id] => 41 [time] =>
> 1346352999 [answer] => [answer_type] => close [winner] => 0 [canwin]
> => 1 [name] => xxxi ) [3] => Array ( [id] => 9648 [edition_id] => 22 [uid] => 100002256926555 [city_id] => 41 [time] =>
> 1346673357 [answer] => [answer_type] => close [winner] => 0 [canwin]
> => 1 [name] => xxx ) [4] => Array ( [id] => 9649 [edition_id] => 22 [uid] => 1362180726 [city_id] => 41 [time] =>
> 1346674240 [answer] => [answer_type] => close [winner] => 0 [canwin]
> => 1 [name] => xxxk ) [5] => Array ( [id] => 9650 [edition_id] => 22 [uid] => 1047795693 [city_id] => 41 [time] =>
> 1346675955 [answer] => [answer_type] => close [winner] => 0 [canwin]
> => 0 [name] => xxx ) ) [_currentPageNumber:protected] => 1 [_filter:protected] => [_itemCountPerPage:protected] => 25 [_pageCount:protected] => 1 [_pageRange:protected] => 10
> [_pages:protected] => stdClass Object ( [pageCount] => 1
> [itemCountPerPage] => 25 [first] => 1 [current] => 1 [last] => 1
> [pagesInRange] => Array ( [1] => 1 ) [firstPageInRange] => 1
> [lastPageInRange] => 1 [currentItemCount] => 6 [totalItemCount] => 6
> [firstItemNumber] => 1 [lastItemNumber] => 6 ) [_view:protected] => )

我需要按[时间]对其进行asc排序,其中[canwin]==1怎么做?我不擅长zend,这需要我很多小时,而且仍然不知道如何做到

Zend_Paginator使用数据库适配器,因此您只需向适配器中添加一条order()语句:

$adapter = new Zend_Paginator_Adapter_DbSelect($db->select()->from('posts'));
    $adapter->setRowCount(
        $db->select()
           ->from(
                'item_counts',
                array(
                   Zend_Paginator_Adapter_DbSelect::ROW_COUNT_COLUMN => 'post_count'
                )
             )->order(...order criteria here...)
    );
    $paginator = new Zend_Paginator($adapter);