public, private, and protected are all keywords for object-oriented programming. PHP4 doesn't support them so the Cake devs elected to use a system of leading underscores to differentiate them. No underscore assumes a public function, one is for protected, and two means private. But PHP4 is dead to me so I use the keywords (which are familiar from years ago with Java, in any case).
On Sun, Aug 16, 2009 at 11:08 PM, Dave Maharaj :: WidePixels.com<[email protected]> wrote: > > My problem is I have a 2 search functions in 1 controller so I have 2 > different paginations sets. I had a huge $paginate like your below and I > just hated seeing it in the controller so what I have done is > > Controller: > > function index() > { > //get the list of bookmark id's belonging to the logged in > user > $bookmarks = > $this->Bookmark->__getBookmarks($this->Auth->user('id'), > $this->Auth->user('rank')); > > //set the $params to query in the model > $this->paginate['Bookmark'] = > $this->Bookmark->__paginateBookmark($this->Auth->user('id'),$this->Auth->use > r('rank')); > //paginate the list > $data = $this->paginate('Bookmark', array('Bookmark.id' => > $bookmarks)); > $this->set('bookmarks', $data); > } > > So __getBookmarks in the model gets me a list of Bookmark.id's > And > __paginateBookmark() is all the $params like you have below > > Model: > function __paginateBookmark ($auth_id, $rank) > { > $params = array( > 'Download' => array( > 'fields' => array( > 'Download.id', > 'Download.path', > 'COUNT(Download.id) AS count', > 'Download.item_file_id' > ), > 'limit' => 25, > 'order' => array('count' => 'DESC'), > 'group' => array('Download.path'), > 'contain' => array( > 'ItemFile' => array( > 'fields' => array( > 'ItemFile.id', > 'ItemFile.basename', > 'ItemFile.type', > 'ItemFile.item_id' > ), > 'Item' => array( > 'fields' => array('Item.id', > 'Item.name'), > 'Thumbnail' => array( > 'fields' => array( > 'Thumbnail.item_id', > > 'Thumbnail.basename', > > 'Thumbnail.directory', > 'Thumbnail.width', > 'Thumbnail.height' > ) > ) > ) > ) > ) > ) > ); > return $params; > } > > But one thing I see you have that I never did quite understnd is public / > private. I have see other people use it in their code but not sure what that > is for. > > -----Original Message----- > From: brian [mailto:[email protected]] > Sent: August-17-09 12:26 AM > To: [email protected] > Subject: Re: Another Paginate Question > > > On Sun, Aug 16, 2009 at 9:21 PM, Dave Maharaj :: > WidePixels.com<[email protected]> wrote: >> >> Never seen this $this->paginate['Bookmark']['contain'] = before, the >> ['contain'] part I mean >> >> >> So I just use it like a normal find array? >> >> $this->paginate['Bookmark']['contain'] = array('Job' => array('fields' >> => array(so on and on))), >> >> And >> >> $this->paginate['Bookmark']['conditions'] = array('Bookmark.user_id' >> => $this->Auth->user('id')), > > This is from a controller I'm working on right now. > > public $paginate = array( > 'Download' => array( > 'fields' => array( > 'Download.id', > 'Download.path', > 'COUNT(Download.id) AS count', > 'Download.item_file_id' > ), > 'limit' => 25, > 'order' => array('count' => 'DESC'), > 'group' => array('Download.path'), > 'contain' => array( > 'ItemFile' => array( > 'fields' => array( > 'ItemFile.id', > 'ItemFile.basename', > 'ItemFile.type', > 'ItemFile.item_id' > ), > 'Item' => array( > 'fields' => array('Item.id', > 'Item.name'), > 'Thumbnail' => array( > 'fields' => array( > 'Thumbnail.item_id', > > 'Thumbnail.basename', > > 'Thumbnail.directory', > 'Thumbnail.width', > 'Thumbnail.height' > ) > ) > ) > ) > ) > ) > ); > > This is a bit more complex than usual because I'm using COUNT() and GROUP, > but it still shows the contain bit. > > In a particular action, if I wanted to narrow that down, I'd do, eg. > > $this->paginate['Download']['conditions'] = array( > 'Download.foo' => $foo > ); > > And so that condition will be effective for any paginate() calls within this > action only. > >> Is there no easy way to paginate from an array? Use a normal find() >> and pass the result to paginate? > > I'm not sure what you mean by "from an array". AFAIK, it's the *only* way to > set up the params. As for using a normal find(), that's pretty much what the > controller does in the end. That's why the array setup for paginate() is > pretty much the same as find(). > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
