2010-02-19 6 views
5

친구,젠드에서 페이지 매기기

젠드 프레임 워크에서 페이지 매김을 만들고 싶습니다. 나는 ZF에 처음 온 사람입니다.

index.phtml이

<table> 
<tr> 
    <th>Name</th> 
    <th>Quantity</th> 
    <th>&nbsp;</th> 
</tr> 
<?php foreach($this->orders as $order) : ?> 
<tr> 
    <td><?php echo $this->escape($order->name);?></td> 
    <td><?php echo $this->escape($order->quantity);?></td> 
    <td> 
     <a href="<?php echo $this->url(array('controller'=>'index','action'=>'edit', 'id'=>$order->id));?>">Edit</a> 
     <a href="<?php echo $this->url(array('controller'=>'index', 'action'=>'delete', 'id'=>$order->id));?>">Delete</a> 
    </td> 
</tr> 
<?php endforeach; ?> 
</table> 
<p><a href="<?php echo $this->url(array('controller'=>'index','action'=>'add'));?>">Add new album</a></p> 

내 인덱스 컨트롤러 아래에 주어진다 아래 내가 내 ZF 프로젝트에서 무슨에 당신이 기반 도우려고

class IndexController extends Zend_Controller_Action 
{ 
    public function init() 
    { 
     /* Initialize action controller here */ 
    } 

    public function indexAction() 
    { 
     $this->view->title = "My Orders"; 
     $this->view->headTitle($this->view->title, 'PREPEND'); 
     $orders = new Model_DbTable_Orders(); 
     $this->view->orders = $orders->fetchAll(); 
    } 
} 
+0

나는 하나의 회신을 받았는데 내가 노력 만 부분 output.I는 'pagination.phtml'을 만들 생각 얻을에 저장 '뷰/스크립트 /'내 색인에 주어진 줄을 추가 .phtml '$ this-> paginationControl ($ this-> paginator,'Sliding ','pagination.phtml ');하지만 처음 10 개 항목 만 표시되고 다음 - 이전 링크는 표시되지 않습니다. 어떻게 해결합니까? – Rakes

답변

17

입니다.

따라서 Model_DbTable_Order 클래스에서 다음과 같은 메소드를 정의 할 수 있습니다. getOnePageOfOrderEntries()를 다음과 같이

/** 
* Return one page of order entries 
* 
* @param int $page page number 
* @return Zend_Paginator Zend_Paginator 
*/ 
public function getOnePageOfOrderEntries($page=1) { 

    $query = $this->select(); 
    $paginator = new Zend_Paginator(
      new Zend_Paginator_Adapter_DbTableSelect($query) 
    ); 
    $paginator->setItemCountPerPage(100); 
    $paginator->setCurrentPageNumber($page); 
    return $paginator; 
} 

indexAction에서이 같은 수보다 :

<?php if (count($this->paginator)): ?> 
    <table> 
    <tr> 
     <th>Name</th> 
     <th>Quantity</th> 
     <th>&nbsp;</th> 
    </tr> 
      <?php foreach($this->paginator as $order): ?> 

    <tr> 

     <td><?php echo $order->name;?></td> 
     <td><?php echo $order->quantity;?></td> 
     <td><!-- And the rest what you want --></td>   
    </tr> 

    <?php endforeach; ?> 
</table> 
<?php endif; ?> 
    <?php echo $this->paginationControl($this->paginator, 
    'Sliding','partial/my_pagination_control.phtml'); ?> 
: 당신의 index.phtml에서

public function indexAction() 
{ 
    $this->view->title = "My Orders"; 
    $this->view->headTitle($this->view->title, 'PREPEND'); 
    $orders = new Model_DbTable_Orders(); 
    //$this->view->orders = $orders->fetchAll(); 

    $page = $this->_request->getParam('page'); 
    if (empty($page)) { $page = 1; } 

    $paginator = $orders->getOnePageOfOrderEntries($page); 
    $this->view->paginator = $paginator; 

} 

당신이 비슷한을 가질 수보기

여기서 my_pagination_control.phtml은 다음과 같습니다 (이것은 복사하여 붙여 넣기 한 것이며 ZF Reference에서 인용 한 것입니다) :

<?php if ($this->pageCount): ?> 
    <div class="paginationControl"> 
    <!-- Previous page link --> 
    <?php if (isset($this->previous)): ?> 
    <a href="<?php echo $this->url(array('page' => $this->previous)); ?>"> 
    Previous 
     </a> <span class="bar"> | </span> 
     <?php else: ?> 
     <span class="disabled"> Previous</span> <span class="bar"> | </span> 
<?php endif; ?> 
<!-- Numbered page links --> 
<?php foreach ($this->pagesInRange as $page): ?> 
    <?php if ($page != $this->current): ?> 
    <a href="<?php echo $this->url(array('page' => $page)); ?>"> 
     <?php echo $page; ?> 
    </a> <span class="bar"> | </span> 
    <?php else: ?> 
    <?php echo $page; ?> <span class="bar"> | </span> 
    <?php endif; ?> 
<?php endforeach; ?> 
<!-- Next page link --> 
<?php if (isset($this->next)): ?> 
    <a href="<?php echo $this->url(array('page' => $this->next)); ?>"> 
    Next 
    </a> 
<?php else: ?> 
    <span class="disabled">Next </span> 
<?php endif; ?> 
</div> 
<?php endif; ?> 

유용 할 것입니다.

+1

+1은 전체 배열 대신에'new Zend_Paginator_Adapter_DbTableSelect()'를 사용합니다. 모델로부터'Zend_Paginator'를 리턴합니다. – chelmertz

+0

paginator를 반환하는 모델의 경우 +1 : –

+0

URL에 추가/action/page/pageno를 추가합니다. 내 이미지와 CSS가 제대로 표시되지 않습니다. 원인은 무엇입니까? 내 이미지와 CSS를로드하는 방법? – shorif2000