<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 分頁(Pagination) # 分頁(Pagination) The process of pagination takes place when we need to present big groups of arbitrary data gradually. Phalcon\\Paginator offers afast and convenient way to split these sets of data browsable pages. ### 數據適配器(Data Adapters) This component makes use of adapters to encapsulate different sources of data: AdapterDescriptionNativeArrayUse a PHP array as source dataModelUse a Phalcon\\Mvc\\Model\\Resultset object as source data. Since PDO doesn't support scrollable cursors this adapter shouldn't be used to paginate a large number of recordsQueryBuilderUse a Phalcon\\Mvc\\Model\\Query\\Builder object as source data### 示例(Examples) In the example below, the paginator will use as its source data the result of a query from a model, and limit the displayed data to 10 records per page: ``` <pre class="calibre14">``` <?php use Phalcon\Paginator\Adapter\Model as PaginatorModel; // Current page to show // In a controller this can be: // $this->request->getQuery('page', 'int'); // GET // $this->request->getPost('page', 'int'); // POST $currentPage = (int) $_GET["page"]; // The data set to paginate $robots = Robots::find(); // Create a Model paginator, show 10 rows by page starting from $currentPage $paginator = new PaginatorModel( array( "data" => $robots, "limit" => 10, "page" => $currentPage ) ); // Get the paginated results $page = $paginator->getPaginate(); ``` ``` Variable $currentPage controls the page to be displayed. The $paginator->getPaginate() returns a $pageobject that contains the paginated data. It can be used for generating the pagination: ``` <pre class="calibre14">``` <table> <tr> <th>Id</th> <th>Name</th> <th>Type</th> </tr> <?php foreach ($page->items as $item) { ?> <tr> <td><?php echo $item->id; ?></td> <td><?php echo $item->name; ?></td> <td><?php echo $item->type; ?></td> </tr> <?php } ?> </table> ``` ``` The $page object also contains navigation data: ``` <pre class="calibre14">``` <a href="/robots/search">First</a> <a href="/robots/search?page=<?= $page->before; ?>">Previous</a> <a href="/robots/search?page=<?= $page->next; ?>">Next</a> <a href="/robots/search?page=<?= $page->last; ?>">Last</a> <?php echo "You are in page ", $page->current, " of ", $page->total_pages; ?> ``` ``` ### 適配器使用(Adapters Usage) An example of the source data that must be used for each adapter: ``` <pre class="calibre14">``` <?php use Phalcon\Paginator\Adapter\Model as PaginatorModel; use Phalcon\Paginator\Adapter\NativeArray as PaginatorArray; use Phalcon\Paginator\Adapter\QueryBuilder as PaginatorQueryBuilder; // Passing a resultset as data $paginator = new PaginatorModel( array( "data" => Products::find(), "limit" => 10, "page" => $currentPage ) ); // Passing an array as data $paginator = new PaginatorArray( array( "data" => array( array('id' => 1, 'name' => 'Artichoke'), array('id' => 2, 'name' => 'Carrots'), array('id' => 3, 'name' => 'Beet'), array('id' => 4, 'name' => 'Lettuce'), array('id' => 5, 'name' => '') ), "limit" => 2, "page" => $currentPage ) ); // Passing a querybuilder as data $builder = $this->modelsManager->createBuilder() ->columns('id, name') ->from('Robots') ->orderBy('name'); $paginator = new PaginatorQueryBuilder( array( "builder" => $builder, "limit" => 20, "page" => 1 ) ); ``` ``` ### 頁面屬性(Page Attributes) The $page object has the following attributes: AttributeDescriptionitemsThe set of records to be displayed at the current pagecurrentThe current pagebeforeThe previous page to the current onenextThe next page to the current onelastThe last page in the set of recordstotal\_pagesThe number of pagestotal\_itemsThe number of items in the source data### 自定義適配器(Implementing your own adapters) The [*Phalcon\\Paginator\\AdapterInterface*](#) interface must be implemented in order to create your own paginator adapters or extend the existing ones: ``` <pre class="calibre14">``` <?php use Phalcon\Paginator\AdapterInterface as PaginatorInterface; class MyPaginator implements PaginatorInterface { /** * Adapter constructor * * @param array $config */ public function __construct($config); /** * Set the current page number * * @param int $page */ public function setCurrentPage($page); /** * Returns a slice of the resultset to show in the pagination * * @return stdClass */ public function getPaginate(); } ``` ``` | - [索引](# "總目錄") - [下一頁](# "使用緩存提高性能(Improving Performance with Cache)") | - [上一頁](# "讀取配置(Reading Configurations)") |
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看