Saturday, 5 November 2011

Paging in ZEND

Code for pagination.php

You Can Check the Paging Site : Amrit

   <?php
$baseurl=Zend_Controller_Front::getInstance()->getBaseUrl();
$image=$baseurl."/public/";

//-------------------------For query string -----------------------------------------------

$start_array = array();
$next_array = array();
$previous_array = array();
$current_array = array();
$last_array = array();

//print_r('BatchID='.$this->sproject);

if($this->prop_type !='' || $this->choose_size1 !='' || $this->zonesize !=''){

        $start_array['page'] = $this->first;
        $next_array['page'] = $this->next;
        $previous_array['page'] = $this->previous;
        $last_array['page'] = $this->last;

        if($this->sproject !=''){
        $start_array['prop_type'] =$this->prop_type;
        $next_array['prop_type'] = $this->prop_type;
        $previous_array['prop_type'] = $this->prop_type;
        $last_array['prop_type'] = $this->prop_type;
        }
      
        if($this->choose_size1 !=''){
        $start_array['choose_size1'] =$this->choose_size1;
        $next_array['choose_size1'] = $this->choose_size1;
        $previous_array['choose_size1'] = $this->choose_size1;
        $last_array['choose_size1'] = $this->choose_size1;
        }
      
        if($this->zonesize !=''){
        $start_array['zonesize'] =$this->zonesize;
        $next_array['zonesize'] = $this->zonesize;
        $previous_array['zonesize'] = $this->zonesize;
        $last_array['zonesize'] = $this->zonesize;
        }
      
        if($this->submit !=''){
        $start_array['submit'] =$this->submit;
        $next_array['submit'] = $this->submit;
        $previous_array['submit'] = $this->submit;
        $last_array['submit'] = $this->submit;
    }
}
    else{
        $start_array['page']= $this->first;
        $next_array['page'] = $this->next;
        $previous_array['page'] = $this->previous;
        $last_array['page'] = $this->last;
    }



//-------------------------For query string -----------------------------------------------

?>
    <style>
    .paging
    {
    color:#0066FF;
    text-align:center;
    font-family:Verdana, Arial, Helvetica, sans-serif;
    font-size:11px;
    }
.paging a
{
color:#000;
text-decoration:none;
padding:0 3px;
font-size:11px;
}
.paging a:hover{color:#0066ff; text-decoration:none;}
.paging a.active{color:#009900; text-decoration:none;}

    </style>
  
    <div class='paging' style='width:100%'>

    <div style='float:left;width:28%'>

    </div>

    <div style='width:100%;'>
   <!-- First page link -->
       <?php if (isset($this->previous)): ?>
             <a href="<?php echo  $this->url($start_array); ?>">Start</a> |
       <?php else: ?>
               <span class="disabled">Start</span> |
       <?php endif; ?>
 
       <!-- Previous page link -->
 
       <?php if (isset($this->previous)): ?>
             <a href="<?php echo  $this->url($previous_array); ?>">&lt; Previous</a> |
       <?php else: ?>
           <span class="disabled">&lt; Previous</span> |
       <?php endif; ?>
       <!-- Numbered page links -->
       <?php foreach ($this->pagesInRange as $page): ?>
           <?php if ($page != $this->current):
$current_array['page'] = $page;

if(!empty($this->prop_type)){
$current_array['prop_type'] = $this->prop_type;
}

if(!empty($this->choose_size1)){
$current_array['choose_size1'] = $this->choose_size1;
}

if(!empty($this->zonesize)){
$current_array['zonesize'] = $this->zonesize;
}

if(!empty($this->submit)){
$current_array['submit'] = $this->submit;
}

//echo '<pre>';print_r($next_array);die;
?>
       <a href="<?php echo  $this->url($current_array); ?>"><?php echo  $page; ?></a>
       <?php else: ?>
       <?php echo  $page; ?>
       <?php endif; ?>
       <?php endforeach; ?>
       <!-- Next page link -->
       <?php if (isset($this->next)): ?>
             | <a href="<?php echo  $this->url($next_array); ?>">Next &gt;</a> |
       <?php else: ?>
           | <span class="disabled">Next &gt;</span> |
       <?php endif; ?>
       <!-- Last page link -->
       <?php if (isset($this->next)): ?>
             <a href="<?php echo  $this->url($last_array); ?>">End</a>
       <?php else: ?>
           <span class="disabled">End</span>
       <?php endif; ?>
       &nbsp; Page <?php echo  $this->current; ?> of <?php echo  $this->last; ?>


    </div>

    </div>





Code for View page such as abc.php 

Paste the code if paging is start.

<? if(count($this->dirdata)>30){ ?>
    <tr height="25">
    <td colspan="13" align="center" bordercolor="#333333" bgcolor="#ffffff" class="error1" >
    <?=$this->paginationControl($this->paginator, 'Sliding', 'pagination.php',$this->postArr);?></td>
    </tr>
<? }?>





Code for Controller

        /* Start code for Paging selected*/   
                   
                    $postArr = $_POST;//print_r($postArr);die;
                    if($this->getRequest()->isPost()  || $this->_getParam('page') != '')
                    { //echo '<pre>';print_r($_POST);die;
                        if($this->getRequest()->isPost())
                            {
                                $postArr = $_POST;//echo '<pre>';print_r($_POST);
                            }
                    else{
                        $postArr = array("prop_type"=>$this->_getParam('prop_type'),
                                       "choose_size1"=>$this->_getParam('choose_size1'),
                                       "zonesize"=>$this->_getParam('zonesize'),
                                       "submit"=>$this->_getParam('submit'));//echo "<pre>";print_r($postArr);die;
                            }       
                    } 

/* End code for Paging selected*/   

        $page=$this->_getParam('page',1);
        $paginator = Zend_Paginator::factory($dirdata);
        $pagelimit=$paginator->setItemCountPerPage(30);
        $paginator->setCurrentPageNumber($page);
        $this->view->paginator=$paginator;
        $this->view->pageID=$page;
       
        $this->view->postArr = $postArr;  

Facebook Profile : Rajneesh Gautam

1 comment: