logo

Pagination Across Models / Associations

logo

For a CakePHP n00b the pagination thing might seem a bit complicated. Well to be frank it is in someways. For instance you can only currently paginate stuff easily when there is a model involved!

For instance here is a pagination with a deep association:

$this->UserProfile->User->Friend->recursive = -1;
		$this->set('userFriends', $this->paginate($this->UserProfile->User->Friend, 
			array('Friend.user_id' => $userid, 'Friend.accepted' => 1)));
 
		$this->set('userFriendsWaiting', $this->paginate($this->UserProfile->User->Friend,
				array('Friend.user_id' => $userid, 'Friend.accepted' => 0, 'Friend.rejected' => 0)));
 
		$this->set('userFriendsRejected', $this->paginate($this->UserProfile->User->Friend,
				array('Friend.user_id' => $userid, 'Friend.accepted' => 0, 'Friend.rejected' => 1)));

in this it is to ensure that you have the paginate var set in your Friend Model – and that each conditions field (the stuff in the array() is prefixed with the table of this model

Hope this clears it up

Share with your friends and help out this site:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogosphere News
  • E-mail this story to a friend!
  • Identi.ca
  • LinkedIn
  • Live
  • MisterWong
  • MySpace
  • Ping.fm
  • Reddit
  • RSS
  • Slashdot
  • StumbleUpon
  • Suggest to Techmeme via Twitter
  • Technorati
  • Tumblr
  • Twitter
  • Yahoo! Bookmarks
  • Yahoo! Buzz
logo
logo
Powered by Nu Order Webs