Zend Pagination example, Zend Framework 1 Pagination & Sorting Tutorial

http://jumnuoy.blogspot.com/2013/06/zend-pagination-example.html
Paginator component is available with Zend Framework v1.6. - 1.12 This component wasn’t available in v1.5. I appreciate Zend for provide such a nice component for pagination. This component, like other component, is so loosely coupled that you can use it wherever you want without worrying about any other component at all.
If you have already created pages and you want to apply pagination to them, it would not be a big deal.

Pagination is three step process.

this select from DB
$sql = "SELECT * FROM table_name ";
$result = $db->fetchAll($sql);

1. add code the controller
$this->paginator = Zend_View_Helper_PaginationControl::setDefaultViewPartial('controls.phtml');
$paginator = Zend_Paginator::factory($result);

$paginator->setItemCountPerPage(2);
$paginator->setPageRange(5);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$this->view->paginator=$paginator;

In the code above we first fetch records from our database. Then instantiate our paginator by writing
$paginator = Zend_Paginator::factory($result);

2. Create template file as controls.phtml in your "/application/view/script/" folder and place the following code
<?php 
if ($this->pageCount): ?>
<div class="fg-toolbar tableFooter">
<div class="dataTables_info" id="checkAll_info">
<?php echo $this->firstItemNumber; ?> - <?php echo $this->lastItemNumber; ?> of <?php echo $this->totalItemCount; ?>
</div>



<div class="dataTables_paginate paging_full_numbers" id="checkAll_paginate">
<!-- First page link -->
<?php if (isset($this->previous)): ?>
<a class="first paginate_button" tabindex="0" id="checkAll_first" href="?page=<?php echo $this->first; ?>">First</a>
<?php else: ?>
<a class="first paginate_button paginate_button_disabled" tabindex="0" id="checkAll_first">First</a>
<?php endif; ?>

<!-- end First page link -->

<!-- Previous page link -->
<?php if (isset($this->previous)): ?>
<a class="previous paginate_button" tabindex="0" id="checkAll_previous" href="?page=<?php echo $this->previous; ?>">Previous</a>
<?php else: ?>
<a class="previous paginate_button paginate_button_disabled" tabindex="0" id="checkAll_previous">Previous</a>
<?php endif; ?>
<!-- end Previous page link -->

<span>
<?php foreach ($this->pagesInRange as $page): ?>
<?php if($page == $this->current) {?>
<a class="paginate_active" tabindex="0"><?php echo $page; ?></a>
<?php } else {?>
<a class="paginate_button" tabindex="0" href="?page=<?php echo $page; ?>"><?php echo $page; ?></a>

<?php }?>
<?php endforeach; ?>
</span>

<!-- Next page link -->
<?php if (isset($this->next)): ?>
<a class="next paginate_button" tabindex="0" id="checkAll_next" href="?page=<?php echo $this->next;?>">Next</a>
<?php else: ?>
<a class="next paginate_button paginate_button_disabled" tabindex="0" id="checkAll_next">Next</a>
<?php endif; ?>
<!-- end Next page link -->

<!-- Last page link -->
<?php if (isset($this->next)): ?>
<a class="last paginate_button" tabindex="0" id="checkAll_last" href="?page=<?php echo $this->last; ?>">Last</a>
<?php else: ?>
<a class="last paginate_button paginate_button_disabled" tabindex="0" id="checkAll_last">Last</a>
<?php endif; ?>
<!-- Last page link -->
  </div>

</div>
<?php endif; ?>


3- put code in view:
<?php echo $this->paginator; ?>

CSS Style
<style>
.dataTables_paginate { float: right; margin-top: 7px; }  .dataTables_paginate .last { margin-right: 0!important; }    /* Two button pagination - previous / next */  .paginate_disabled_previous, .paginate_enabled_previous, .paginate_disabled_next, .paginate_enabled_next { height: 19px; float: left; cursor: pointer; *cursor: hand; color: #111 !important; }  .paginate_disabled_previous:hover, .paginate_enabled_previous:hover, .paginate_disabled_next:hover, .paginate_enabled_next:hover { text-decoration: none !important; }  .paginate_disabled_previous:active, .paginate_enabled_previous:active, .paginate_disabled_next:active, .paginate_enabled_next:active { outline: none; }  .paginate_disabled_previous, .paginate_disabled_next { color: #666 !important; }  .paginate_disabled_previous, .paginate_enabled_previous { padding-left: 23px; }  .paginate_disabled_next, .paginate_enabled_next { padding-right: 23px; margin-left: 10px; }  .paginate_enabled_previous { background: url('../images/tables/back_enabled.png') no-repeat top left; }  .paginate_enabled_previous:hover { background: url('../images/tables/back_enabled_hover.png') no-repeat top left; }  .paginate_disabled_previous { background: url('../images/tables/back_disabled.png') no-repeat top left; }  .paginate_enabled_next { background: url('../images/tables/forward_enabled.png') no-repeat top right; }  .paginate_enabled_next:hover { background: url('../images/tables/forward_enabled_hover.png') no-repeat top right; }  .paginate_disabled_next { background: url('../images/tables/forward_disabled.png') no-repeat top right; }
</style>


Reference:
http://framework.zend.com/manual/1.12/en/zend.paginator.usage.html
http://zendgeek.blogspot.com/2009/07/zend-pagination-example.html 

Paginator component is available with Zend Framework v1.6. - 1.12 This component wasn’t available in v1.5. I appreciate Zend for provide such a nice component for pagination. This component, like other component, is so loosely coupled that you can use it wherever you want without worrying about any other component at all.
If you have already created pages and you want to apply pagination to them, it would not be a big deal.

Pagination is three step process.

this select from DB
$sql = "SELECT * FROM table_name ";
$result = $db->fetchAll($sql);

1. add code the controller
$this->paginator = Zend_View_Helper_PaginationControl::setDefaultViewPartial('controls.phtml');
$paginator = Zend_Paginator::factory($result);

$paginator->setItemCountPerPage(2);
$paginator->setPageRange(5);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$this->view->paginator=$paginator;

In the code above we first fetch records from our database. Then instantiate our paginator by writing
$paginator = Zend_Paginator::factory($result);

2. Create template file as controls.phtml in your "/application/view/script/" folder and place the following code
<?php 
if ($this->pageCount): ?>
<div class="fg-toolbar tableFooter">
<div class="dataTables_info" id="checkAll_info">
<?php echo $this->firstItemNumber; ?> - <?php echo $this->lastItemNumber; ?> of <?php echo $this->totalItemCount; ?>
</div>



<div class="dataTables_paginate paging_full_numbers" id="checkAll_paginate">
<!-- First page link -->
<?php if (isset($this->previous)): ?>
<a class="first paginate_button" tabindex="0" id="checkAll_first" href="?page=<?php echo $this->first; ?>">First</a>
<?php else: ?>
<a class="first paginate_button paginate_button_disabled" tabindex="0" id="checkAll_first">First</a>
<?php endif; ?>

<!-- end First page link -->

<!-- Previous page link -->
<?php if (isset($this->previous)): ?>
<a class="previous paginate_button" tabindex="0" id="checkAll_previous" href="?page=<?php echo $this->previous; ?>">Previous</a>
<?php else: ?>
<a class="previous paginate_button paginate_button_disabled" tabindex="0" id="checkAll_previous">Previous</a>
<?php endif; ?>
<!-- end Previous page link -->

<span>
<?php foreach ($this->pagesInRange as $page): ?>
<?php if($page == $this->current) {?>
<a class="paginate_active" tabindex="0"><?php echo $page; ?></a>
<?php } else {?>
<a class="paginate_button" tabindex="0" href="?page=<?php echo $page; ?>"><?php echo $page; ?></a>

<?php }?>
<?php endforeach; ?>
</span>

<!-- Next page link -->
<?php if (isset($this->next)): ?>
<a class="next paginate_button" tabindex="0" id="checkAll_next" href="?page=<?php echo $this->next;?>">Next</a>
<?php else: ?>
<a class="next paginate_button paginate_button_disabled" tabindex="0" id="checkAll_next">Next</a>
<?php endif; ?>
<!-- end Next page link -->

<!-- Last page link -->
<?php if (isset($this->next)): ?>
<a class="last paginate_button" tabindex="0" id="checkAll_last" href="?page=<?php echo $this->last; ?>">Last</a>
<?php else: ?>
<a class="last paginate_button paginate_button_disabled" tabindex="0" id="checkAll_last">Last</a>
<?php endif; ?>
<!-- Last page link -->
  </div>

</div>
<?php endif; ?>


3- put code in view:
<?php echo $this->paginator; ?>

CSS Style
<style>
.dataTables_paginate { float: right; margin-top: 7px; }  .dataTables_paginate .last { margin-right: 0!important; }    /* Two button pagination - previous / next */  .paginate_disabled_previous, .paginate_enabled_previous, .paginate_disabled_next, .paginate_enabled_next { height: 19px; float: left; cursor: pointer; *cursor: hand; color: #111 !important; }  .paginate_disabled_previous:hover, .paginate_enabled_previous:hover, .paginate_disabled_next:hover, .paginate_enabled_next:hover { text-decoration: none !important; }  .paginate_disabled_previous:active, .paginate_enabled_previous:active, .paginate_disabled_next:active, .paginate_enabled_next:active { outline: none; }  .paginate_disabled_previous, .paginate_disabled_next { color: #666 !important; }  .paginate_disabled_previous, .paginate_enabled_previous { padding-left: 23px; }  .paginate_disabled_next, .paginate_enabled_next { padding-right: 23px; margin-left: 10px; }  .paginate_enabled_previous { background: url('../images/tables/back_enabled.png') no-repeat top left; }  .paginate_enabled_previous:hover { background: url('../images/tables/back_enabled_hover.png') no-repeat top left; }  .paginate_disabled_previous { background: url('../images/tables/back_disabled.png') no-repeat top left; }  .paginate_enabled_next { background: url('../images/tables/forward_enabled.png') no-repeat top right; }  .paginate_enabled_next:hover { background: url('../images/tables/forward_enabled_hover.png') no-repeat top right; }  .paginate_disabled_next { background: url('../images/tables/forward_disabled.png') no-repeat top right; }
</style>


Reference:
http://framework.zend.com/manual/1.12/en/zend.paginator.usage.html
http://zendgeek.blogspot.com/2009/07/zend-pagination-example.html 

0 comments:

Post a Comment

Followers

រឿង ដែលខានមើលមិនបាន

Contact us

Name

Email *

Message *

Your Language

Online

Copyright 2009 Simplex Celebs All rights reserved Designed by www.sruol9.com