Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-06-2007, 07:47 AM
quannm0410l's Avatar
Junior Member
 
Join Date: Mar 2007
Posts: 11
Default Paging in mvc

anyone tells me how to create paging in zend fr ? thank you
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-07-2007, 02:12 AM
quannm0410l's Avatar
Junior Member
 
Join Date: Mar 2007
Posts: 11
Unhappy

Zend_View_Pagination helpppppppp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-07-2007, 03:35 PM
SpotSec's Avatar
Senior Member
 
Join Date: Feb 2007
Location: United States
Posts: 121
Default

There's a Zend_View_Pagination? Thought that never made it through?
Anyways all I know for now is for pagination you either have to implement it yourself or use some third party pagination methods.
__________________
Zym Framework - A Zend Framework extension library w/ demo app

SpotSec Blog:
http://spotsec.com/blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-07-2007, 05:56 PM
Member
 
Join Date: Mar 2007
Posts: 41
Default

Check this
It's in czech, but try it...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-31-2007, 04:25 PM
Junior Member
 
Join Date: Jul 2007
Posts: 2
Default Pagination View Helper

Pagination is basically getting the limit and offet sent to the SQL statement like:
"SELECT * FROM myTable LIMIT $numRowsToGet, $getRowsFromOffset"
I created a PAGINATOR view helper class to handle pagination. It received $params and $total from the controller.
Here is the code. Any suggestions / comments would be great.

PHP Code:

/**
*    PAGINATION HELPER
    
    $params = array(
        'limit' = int,
        'offset' = int
    )
    $total = int -> total numbers of results
*
/**/
class XV_View_Helper_Paginator{
    
    public 
$view;

    public function 
setView(Zend_View_Interface $view)
    {
        
$this->view $view;
    }
    public function 
paginator(){
        
$total =  $this->view->contactsPage['count']; 
        
$params $this->view->params;
        
// set offsets
        
$firstOffset 0;
        
$prevOffset $params['offset'] - $params['limit'];
        
$nextOffset $params['offset'] + $params['limit'];
        
$lastOffset = (round$total $params['limit']) * $params['limit']) - $params['limit'];
        
// build pagination links
        
$firstHTML = ($params['offset'] == $firstOffset ) ? '&laquo; First' '<a href="../../../XV/View/Helper/'$this->buildUrl(0$params['limit']) . '">&laquo; First</a>'
        
$prevHTML = ($prevOffset ) ? ' &lt; Prev' '<a href="../../../XV/View/Helper/'$this->buildUrl($prevOffset$params['limit']) . '">&lt; Prev</a>';
        
$nextHTML = ($nextOffset $total) ? 'Next &gt;' '<a href="../../../XV/View/Helper/'$this->buildUrl($nextOffset$params['limit']) . '">Next &gt; </a>';
        
$lastHTML = ($nextOffset $total) ? 'Last &raquo;' '<a href="../../../XV/View/Helper/'$this->buildUrl($lastOffset$params['limit']) . '">Last &raquo;</a>';
        
// set page and record vars
        
$currentPage = ($params['offset'] / $params['limit']) + ;
        
$totalPages round($lastOffset $params['limit']) + 1;
        
//$recordFrom
        
$recordTo = ($nextOffset $total) ? $total $nextOffset;
        
// build pagination table
        
$pagiTableHTML '<table width="" class="pagi">
                    <tr>
                        <td class="link">'
.$firstHTML.'</td>
                        <td class="link">'
.$prevHTML.'</td>
                        <td class="pageText">Page '
$currentPage .' of '$totalPages .'</td>
                        <td class="link">'
.$nextHTML.'</td>
                        <td class="link">'
.$lastHTML.'</td>
                        <td class="recordText">Displaying '
.($params['offset']+1).' - '.$recordTo.' of '.$total.' Records</td>
                    </tr>
                    </table>'
;
        return 
$pagiTableHTML;
    }
    public function 
buildUrl($offset$limit){
        return 
$this->view->modulePath ."/contact?offset=$offset&limit=$limit";
    }

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 08-16-2007, 08:55 AM
Member
 
Join Date: Aug 2007
Location: Sweden
Posts: 52
Send a message via MSN to Leif.Högberg
Default My take on paging

The db stuff is handled outside of the paginator.
This could easily be modified in to a helper.

PHP Code:
<?php
/*
        Author: Leif Högberg @ Gomitech

    paging algorithm is based upon code from the punBB project at www.punbb.org
    
    Usage:
    $P = new Gomi_Paginator();

    $P->setLinkUrl('foo.php?%PAGE%');
    $P->setLinkHTML('<a href="%URL%">%PAGE%</a>');
    $P->setCurrentHTML('<b>%PAGE%</b>');
    
    echo $P->generateLinkString(6); // Will output "1 2 3 ... 6"
*/
class Gomi_Paginator
{

    protected 
$linkUrl '%PAGE%';
    protected 
$linkHTML '<a href="%URL%">%PAGE%</a>';
    protected 
$currentHTML '<b>%PAGE%</b>';
    protected 
$linkAllPages false;
    protected 
$pageSeparator '&nbsp;';
        
    public function 
getLinkUrl()
    {
        return 
$this->linkUrl;
    }    
    public function 
setLinkUrl($url)
    {
        
$this->linkUrl $url;
    }

    public function 
getLinkHTML()
    {
        return 
$this->linkHTML;
    }
    public function 
setLinkHTML($linkHTML)
    {
        
$this->linkHTML $linkHTML;
    }
    
    public function 
getCurrentHTML()
    {
        return 
$this->currentHTML;
    }
    public function 
setCurrentHTML($html)
    {
        
$this->currentHTML $html;
    }
    
    public function 
getLinkAllPages()
    {
        return 
$this->linkAllPages;
    }
    public function 
setLinkAllPages($bool)
    {
        
$this->linkAllPages $bool;
    }
    
    public function 
getPageSeparator()
    {
        return 
$this->pageSeparator;
    }
    public function 
setPageSeparator($str)
    {
        
$this->pageSeparator $str;
    }
    
    private function 
generateCurrentStringForPage($page)
    {
        return 
str_replace('%PAGE%'$page$this->getCurrentHTML());
    }
    private function 
generateLinkStringForPage($page)
    {
        return 
str_replace(array('%URL%''%PAGE%'), array($this->getLinkUrl(), $page), $this->getLinkHTML());
    }
    
    private function 
generate($totalPages$currentPage 1)
    {
        
$pages = array();

            
//just one page
        
if ($totalPages <= 1)
        {
            if (
$this->getLinkAllPages())
            {
                
$pages[] = $this->generateLinkStringForPage(1);
            }
            else
            {
                
$pages[] = $this->generateCurrentStringForPage(1);
            }
        }
            
//more than one page
        
else
        {
            if (
$currentPage 3)
            {
                
$pages[] = $this->generateLinkStringForPage(1);

                if (
$currentPage != 4)
                    
$pages[] = '&hellip;';
            }

            for (
$index $currentPage 2$stop $currentPage 3$index $stop; ++$index)
            {
                if (
$index || $index $totalPages)
                    continue;
                else if (
$index != $currentPage || $this->getLinkAllPages())
                    
$pages[] = $this->generateLinkStringForPage($index);
                else
                    
$pages[] = $this->generateCurrentStringForPage($index);
            }

            if (
$currentPage <= ($totalPages 3))
            {
                if (
$currentPage != ($totalPages 3))
                    
$pages[] = '&hellip;';

                
$pages[] = $this->generateLinkStringForPage($totalPages);
            }
        }
        
        return 
$pages;
    }
    
    public function 
generateLinkString($totalPages$currentPage 1)
    {
        
$pages $this->generate($totalPages$currentPage);
        return 
implode($this->getPageSeparator(), $pages);
    }

}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 08-28-2007, 06:53 PM
Junior Member
 
Join Date: Aug 2007
Posts: 1
Lightbulb Simple pagination class

Hello everybody, I found this simple yet powerful pagination class that works over arrays collections, so it can be used for paginating database resultsets, XML documents or everything else convertible to arrays in PHP language.
It's provided as a zip package consisting on the class source code and a quick start manual.
Hope you like it.
Attached Files
File Type: zip PaginateIt.zip (5.3 KB, 164 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 09-02-2007, 07:45 PM
Elemental's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 122
Default

this post at Digital Fashion is designed for ZF (uses Zend_Db etc.)

However, I ended up using AJAX for this. The controller runs the query and returns all results to the browser, then I made a javascript pagination object. This is handy as I don't have to worry about limits and offsets for my queries and all the sorting is done on the client side. jQuery makes this a breeze.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 07-21-2008, 03:15 PM
Junior Member
 
Join Date: Jul 2008
Posts: 1
Default Ajax-ZF-Pagination

Elemental, would you mind sharing your ajax pagination function. If not, can you please post a copy here.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 09:12 PM.