How to specify route with parameter in paginationControl?

I am trying to create a pagination in my news feed. I have two modes in the news feed: All news feeds and Category feeds. Pagination for all feeds works fine, but I am having problems paginating "feed by category".

I am using paginationControl like this:

<?=$this->paginationControl(
    $this->news,
    'Sliding',
    'pagination_control',
    array('route' => 'news/category')
)?>

      

Config route news/category

:

'category' => array(
    'type' => 'Segment',
    'options' => array(
        'route' => '/:category[/page-:page]',
        'constraints' => array(
            'category'     => '[a-z]+',
            'page'     => '[1-9][0-9]*',
        ),
        'defaults' => array(
            'controller' => 'News\Controller\Item',
            'action'     => 'category',
            'page'      => 1,
        )
    ),
    'may_terminate' => true,
),

      

So I need to specify the parameter category. I am trying this:

<?=$this->paginationControl(                                                                 
    $this->news,                                                                             
    'Sliding',                                                                               
    'pagination_control',                                                                    
    array('route' => 'news/category', array('category' => $this->category->getUrl()))        
)?>          

      

But I get the error "Missing parameter ...":

enter image description here

It looks like it is not possible to set the parameter via paginationControl.

How to specify route with parameter in paginationControl correctly ?

Update 1

My paginationControl looks like this:

<?php if ($this->pageCount > 1): ?>
    <div>
        <ul class="pagination pagination-sm">
            <!-- Previous page link -->
            <?php if (isset($this->previous)): ?>
                <li>
                    <a href="<?=$this->url($this->route, array('page' => $this->previous))?>">
                        &laquo;
                    </a>
                </li>
            <? else: ?>
                <li class="disabled"><span>&laquo;</span></li>
            <? endif; ?>

            <!-- Numbered page links -->
            <? foreach ($this->pagesInRange as $page): ?>
                <? if ($page != $this->current): ?>
                    <li>
                        <a href="<?=$this->url($this->route, array('page' => $page))?>">
                            <?=$page?>
                        </a>
                    </li>
                <? else: ?>
                    <li class="active"><span><?=$page?></span></li>
                <? endif; ?>
            <? endforeach; ?>

            <!-- Next page link -->
            <?php if (isset($this->next)): ?>
                <li>
                    <a href="<?=$this->url($this->route, array('page' => $this->next))?>">
                        &raquo;
                    </a>
                </li>
            <?php else: ?>
                <li class="disabled"><span>&raquo;</span></li>
            <?php endif; ?>
        </ul>
    </div>
    <div>
        <span class="small grey"><?=" ".$this->current."  ".$this->pageCount?></span>
    </div>
<?php endif; ?>

      

+3


source to share


1 answer


You have to pass all additional parameters as an associative array at the end as @rianattow said. Thus, all these parameters will be available in part pagination_control.phtml

via$this->paramname

Example:

echo $this->paginationControl(                                                                 
     $this->news,                                                                             
     'Sliding',                                                                               
     'pagination_control',                                                                    
     array( 'route' => 'news/category', 'category' => 'banana')
    );

      

This detail is described in the paginator documentation :



The fourth and final parameter is reserved for an optional associative array of additional variables that you want to retrieve in your view (accessible via $ this). For example, these values ​​can include additional URL parameters for linking to pages.

I think the other missing item is generating the url using route names. Instead of passing the url to the helper paginationControl()

as an argument, try to generate the url inside the partial split like so:

<a href="<?
    echo $this->url($this->route, array('page' => $page, 'category' => $this->category))
?>">

      

Hope it helps.

+7


source







All Articles