I'm building a dynamic view (Page
) that consists of multiple elements (widgets) called via $this->element('messages_unread')
. Some of these elements need data that is not related to the Page model.
In real life words: my users will be able to construct their own Page by choosing from a multitude of elements ("top 5 posts", "10 unread messages", etc...)
I get the data by calling $this->requestAction(array('controller'=>'events','action'=>'archive')
from within the element, the url-variables differ per element .
I'm aware of the fact that requestAction()
is expensive and I plan on limiting the costs by proper caching.
The actual question:
My problem is Pagination. When I'm in the Page
view and call requestAction('/events/archive')
the PaginatorHelper in the Page view will be unaware of the Event
model and its paginator variables and $this->Paginator->next()
etc... will not work.
How can I implement proper Pagination? I've tried to set the model by calling $this->Paginator->options(array('model'=>'Event'))
but that doesn't work.
Do I maybe need to return custom defined Pagination variables in the requestAction
and thus construct my own?
Or is there another approach that maybe even avoids requestAction()
? And keep in mind here that the requested data is unrelated to the Page.
Kind regards, Bart
[Edit] My temporary solution but still open for comments/solutions:
In the requestedAction Event/archive
, return paginator variables along with the data like this:
return array('data'=>$this->paginate(), 'paging' => $this->params['paging']);