Wednesday, March 30, 2011

Re: Paginate pre-ordered list

There is not much going on at all with the Like::getMostLiked()
function. The Like Model works in conjunction with Facebook. FB's Like
button doesn't work so well with password protected pages so I
basically re-wrote their script for the "Like" button and now it does
what I want and then some. The "Likes" still get recorded to FB and
show up on your wall, but I keep track of all the "Like" stats through
my site as well. Users are able to "Like" other users, and that is
what Like::getMostLiked() is doing ... returned a list of the most
liked users.

class Like extends AppModel {

function getMostLiked($limit = null, $page = 1){

$this->primaryKey = 'user_id';
$liked = $this->find('list', array('conditions' => array('Like.count
>' => 0), 'order' => 'count DESC, modified ASC', 'limit' => $limit,
'page' => $page));
$liked = array_flip($liked);
return $liked;
}

}

Like I said, not much there. What I'm really doing is paginating the
users that are "Liked" in the order of greatest to least but there is
no criteria in the User Model to define that order ... it comes from
the Like Model. Using array_push works fine for retrieving the
associated User data and loading the array in the exact order I want
it presented to the view, no problem there. It's no biggie to write my
own pagination for the view, Cake just has me spoiled in many
respects. It's difficult to believe I used to do things the hard
way :)

- ED

On Mar 30, 2:05 pm, ShadowCross <adri...@jps.net> wrote:
> My apologies.  In retrospect, I think the only method in the PaginatorHelper
> that I used when manually loading the helper (and not using
> Controller::paginate()) was PaginatorHelper::sort().
>
> Basically, since you are not using the Controller::paginate() function, you
> pretty much either have to write your own pagination.  In order to be able
> to use Cake's automagic for pagination, you need to be able to express the
> query with the same parameters as a Model->find('all', $options).  What
> exactly are you doing in the Like::getMostLiked() function?

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: