Gadzooks--it works! I had to do a bit of mucking about, and I'm
certain to take a bit of a performance hit, but with the paged cached,
I think I should be ok.

For the record, I got a tip from this post:
http://www.mail-archive.com/cake-php@googlegroups.com/msg46533.html

So, I first added Paginator to the controller that loads my static
pages. I couldn't find a way around this. Then I did the following in
the controller (the requestAction):

public function front_page()
{
        $posts = $this->paginate('Post');
        $paginator = ClassRegistry::getObject('view')->loaded['paginator'];
        $paginator->params = $this->params;
        return compact('posts', 'paginator');
}


Because PostsController doesn't have a view handy, I needed to grab
the Paginator from the view where the request is coming from. Next, I
swapped in the controller's freshly-paginated params and passed it and
the posts back to the element, which looks like:

$result = $this->requestAction('posts/front_page');
$paginator = $result['paginator'];

foreach ($result['posts'] as $post)
{
    ...
}
echo $this->element(
        'paginator_links',
        array('url' => array('controller' => 'posts', 'action' => 'index'))
);

paginator_links is a generic element I drop in to provide paging
links. I made a small adjustment to accept a $url param:

$paginator->options(
        array('url' => isset($url) ? $url : $this->passedArgs)
);

And that's it. I got sidetracked big time, setting stuff in Paginator
inside the controller like so:

$paginator->params['controller'] =
$paginator->Html->params['controller'] = 'posts';
$paginator->action = $paginator->params['action'] =
$paginator->Html->params['action'] = 'index';
$paginator->params['url']['url'] =
$paginator->Html->params['url']['url'] = 'posts/index';

Then, I realised that there was also:

$paginator->Ajax->params['controller'] = 'posts';
$paginator->Ajax->Javascript->params['controller'] = 'posts';
$paginator->Ajax->Form->params['controller'] = 'posts';
$paginator->Ajax->action = 'index';
$paginator->Ajax->params['action'] = 'index';
$paginator->Ajax->Javascript->action = 'index';
$paginator->Ajax->Javascript->params['action'] = 'index';
$paginator->Ajax->Form->action = 'index';
$paginator->Ajax->Form->params['action'] = 'index';
$paginator->Ajax->params['url']['url'] = 'posts/index';
$paginator->Ajax->Javascript->params['url']['url'] = 'posts/index';
$paginator->Ajax->Form->params['url']['url'] = 'posts/index';

I went through all of these, one by one, figuring I'd comment them
out, again, one by one, once I got the damned url to come out
correctly. Nothing doing. But, it turned out that I simply needed to
pass the url as an option.

Anyway, I'd appreciate comments (even the "you're frigging crazy" sort).

On Tue, Feb 17, 2009 at 8:17 PM, brian <bally.z...@gmail.com> wrote:
> I have a front page, served from a modified PagesController, that has
> an element which calls requestAction('posts/front_page') (I know, I
> know) to grab the most recent Posts. At the bottom of the list of
> posts is a link leading to posts/index. What I'd really like to do is
> use paginate() instead of find() so I can set up pagination links.
>
> I'd really rather not use posts/index.ctp as the home page for the
> site. The idea would be to have the pagination links at the bottom of
> the main page point to posts/index, though I'd actually be using ajax
> to refresh the list on the main page.
>
> Now, given that I'm using requestAction() this doesn't seem possible
> ... but I'm trying anyway.
>
> Browsing through the Controller source, I see that I need to have
> $this->params['paging'] set. So, I added Paginator to the controller's
> helpers array and modified the PostsController's action like:
>
> public function front_page()
> {
>        $posts = $this->paginate('Post');
>        return array('posts' => $posts, 'paging' => $this->params['paging']);
> }
>
> In the element, I have (and I know this isn't a great idea):
>
> $result = $this->requestAction('posts/front_page');
> $this->params['paging'] = $result['paging'];
>
> foreach ($result['posts'] as $post)
> {
>    ...
>
> Now, of course, this isn't sufficient, because PaginatorHelper hasn't
> been intialized with the params in PagesController:
>
> Notice (8): Undefined index:  pageCount
> [CORE/cake/libs/view/helpers/paginator.php, line 473]
>
> So, before I head further down this road, does anyone have a
> suggestion for how to do this ... properly?
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to