2017-01-02 7 views
0

В рамках моего проекта Zend Framework у меня есть модуль «базовый актив». В этом я пытаюсь создать нумерацию страниц, которая будет соответствовать следующему маршруту:ZF2 pagination Передача значения с маршрута

'route' => '/video/search[/:search][/:page_reference]', 

Целью стоимости поиска является так же запрос будет выполняться на базе данных, если пользователь нажимает на любом из «следующих «Созданы ссылки на страницы.

Значение для page_reference работает нормально. Это значение для поиска, что я не уверен в том, как заполнить для постраничной:

<li> 
    <a href="<?php echo $this->url(
     $this->route, 
     ['page_reference' => $this->previous , 'search' => $this->search] 
    ); ?>"> << </a> 
</li> 

Следующие попытки не увенчались успехом:

$this->search 
$this->params()->fromRoute('search') 

пагинацию называется с точки зрения использования

{{ paginationControl(result, 'sliding', ['actsministries/asset/searchpaginator', 'AMBase']) }} 

Должен ли я установить значение для поиска в услуг?

ответ

1

1 - Создать помощник вида:

use Zend\View\Helper\AbstractHelper; 

class Requesthelper extends AbstractHelper 
{ 
    protected $request; 

    //get Request 
    public function setRequest($request) 
    { 
     $this->request = $request;  
    } 

    public function getRequest() 
    { 
     return $this->request;  
    } 

    public function __invoke() 
    { 
     return $this->getRequest()->getServer()->get('QUERY_STRING');  
    } 
} 

2 - module.php

public function getViewHelperConfig() 
    { 
     return array(
      'invokables' => array(
      ), 

      'factories' => array(
       'Requesthelper' => function($sm){ 
        $helper = new YourModule\View\Helper\Requesthelper; \\the path to creatd view helper 
        $request = $sm->getServiceLocator()->get('Request'); 
        $helper->setRequest($request); 
        return $helper; 
       } 
      ), 
     ); 
    } 

3 - searchpaginator.phtml:

<?php 
$parameterGet = $this->Requesthelper(); 
if ($parameterGet != ""){ 
    $aParams = explode("&", $parameterGet); 
    foreach($aParams as $key => $value){ 
     if(strpos($value, "page_reference=") !== false){ 
      unset($aParams[$key]); 
     } 
    } 

    $parameterGet = implode("&", $aParams); 

    if($parameterGet != '') 
     $parameterGet = "&".$parameterGet; 
} 

?> 
<?php if ($this->pageCount):?> 
    <div> 
     <ul class="pagination"> 
      <!-- Previous page link --> 
      <?php if (isset($this->previous)): ?> 
       <li> 
        <a href="<?php echo $this->url($this->route); ?>?page_reference=<?php echo $this->previous.$parameterGet; ?>"> 
         &lt;&lt; 
        </a> 
       </li> 
      <?php else: ?> 
       <li class="disabled"> 
        <a href="#"> 
         &lt;&lt; 
        </a> 
       </li> 
      <?php endif; ?> 

      <!-- Numbered page links --> 
      <?php foreach ($this->pagesInRange as $page): ?> 
       <?php if ($page != $this->current): ?> 
        <li> 
         <a href="<?php echo $this->url($this->route);?>?page_reference=<?php echo $page.$parameterGet; ?>"> 
          <?php echo $page; ?> 
         </a> 
        </li> 
       <?php else: ?> 
        <li class="active"> 
         <a href="#"><?php echo $page; ?></a> 
        </li> 
       <?php endif; ?> 
      <?php endforeach; ?> 

      <!-- Next page link --> 
      <?php if (isset($this->next)): ?> 
       <li> 
        <a href="<?php echo $this->url($this->route); ?>?page_reference=<?php echo $this->next.$parameterGet; ?>"> 
         &gt;&gt; 
        </a> 
       </li> 
      <?php else: ?> 
       <li class="disabled"> 
        <a href="#"> 
         &gt;&gt; 
        </a> 
       </li> 
      <?php endif; ?> 
     </ul> 
    </div> 
<?php endif; ?> 

4 - index.phtml

<?php 
// add at the end of the file after the table 
echo $this->paginationControl(
    // the paginator object 
    $this->paginator, 
    // the scrolling style 
    'sliding', 
    // the partial to use to render the control 
    'partial/searchpaginator.phtml', 
    // the route to link to when a user clicks a control link 
    array(
     'route' => '/video/search' 
    ) 
); 
?> 

Надеюсь, это то, что вы ищете

+0

Brilliance. Благодаря! –