Zend Paginator: How to add a custom property on each item?

For programming and general questions on Zend Framework

Zend Paginator: How to add a custom property on each item?

Postby diog6114 on Thu Feb 09, 2017 6:46 pm

Hi,

I have a Zend\Paginator\Paginator instance, and I would like to add a custom property on each item, will be something like this:

Code: Select all
$tagCollection = $this->mapper->fetchAll();
        $currentItems = $tagCollection->getCurrentItems();

        foreach ($currentItems as $item) {
            $item->doubleId = $item->id * 2;
        }


I dont have setCurrentItems method on Pagination class, I see that is $currentItems is private and Traversable.
What should be the best way to achieve this?

Thanks!
diog6114
 
Posts: 3
Joined: Thu Feb 09, 2017 6:42 pm

Re: Zend Paginator: How to add a custom property on each ite

Postby mehm8471 on Thu Feb 09, 2017 8:14 pm

Hello,

You can pass optional properties as the 4th parameter of paginationControl plugin.

For more information: see my blog post http://smozgur.com/blog/zend-framework/pagination-with-zend-paginator/ and especially next post contains custom parameter while calling paginationControl. It would give idea.

Hope it helps.

Suat
mehm8471
 
Posts: 20
Joined: Sat Jun 21, 2014 11:39 pm

Re: Zend Paginator: How to add a custom property on each ite

Postby diog6114 on Thu Feb 09, 2017 10:47 pm

Hi Suat,

I'm appreciate your help! I will take a full read of blog post soon.
I worked with ZF1 in the past, and now with Apigility I'm take some difficulties with Zf3.

Nice to found you!
Regards from Brazil.

Diogo.
diog6114
 
Posts: 3
Joined: Thu Feb 09, 2017 6:42 pm

Re: Zend Paginator: How to add a custom property on each ite

Postby mehm8471 on Fri Feb 10, 2017 12:59 am

Hi Diogo,

I recently started my blog and trying to share what and how I learned ZF and applying in my live projects. That's the reason I started my Online Book Catalog Application Tutorial as I believe it might be a contribution to other valuable tutorials online. I'd love to hear your and your friends' ideas about my blog which is mostly related ZF. Please don't hesitate to share my blog and let me know if you have any questions or suggestions.

Suat
mehm8471
 
Posts: 20
Joined: Sat Jun 21, 2014 11:39 pm

Re: Zend Paginator: How to add a custom property on each ite

Postby diog6114 on Sat Feb 11, 2017 3:52 pm

Hi Suate,

I followed the tutorial on your blog and adapted the code for Apigility application, works well!
But I still with the question... to how to add a custom property, once that paginationControl is a helper for view layer.

At now, to achieve this goal, I'm doing a custom ResultSet and passing on 3 parameter when I create the paginationAdapter on DbSelect constructor.
But the bussines logics it's on ResultSet, on getArrayCopy() method, is this a good approach? Have another recommendation for this case, like a right way?

Thanks in advance.
diog6114
 
Posts: 3
Joined: Thu Feb 09, 2017 6:42 pm

Re: Zend Paginator: How to add a custom property on each ite

Postby mehm8471 on Sat Feb 11, 2017 9:22 pm

Diogo,

Can you send me your model folder in Rest folder so I can look at it?
You can find my contact email in my website.

Suat
mehm8471
 
Posts: 20
Joined: Sat Jun 21, 2014 11:39 pm


Return to Zend Framework

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests