OK. This is getting weird. Now it works for custom query, but it doesn't work when I need default pagination for other actions of the same controller.
The problem is however, with the overriding paginate() and paginateCount() - Cake 1.3 manual and the source code of both, are different. In Cake manual, http://book.cakephp.org/view/1237/Custom-Query-Pagination, it says: function paginate($conditions, $fields, $order, $limit, $page = 1, $recursive = null, $extra = array()) { ... } But in the source code I see: function paginate($object = null, $scope = array(), $whitelist = array()) { ...} So which one is it? And I also seem unable to find paginateCount() definition in source code (At least that's what Netbean's Find is uinable to find) BTW, this is how I defined them in my model: function paginate($conditions=null, $fields=null, $order=null, $limit=null, $page = 1, $recursive = null, $extra = array()) { if (isset($conditions['sql'])) { $recursive = -1; $query = $conditions['sql']; unset($conditions['sql']); $query .= ' LIMIT '.($page-1)*$limit.','.$limit; return $this->query($query); } else{ return parent::paginate($conditions, $fields, $order, $limit, $page,$recursive, $extra); } } function paginateCount($conditions = null, $recursive = 0, $extra = array()) { if (isset($conditions['sql'])) { $sql = $this->mmPaginateCount; //I assign this from controller, i need it this way. $results = $this->query($sql); return $results[0][0]['c']; } else{ return parent::paginateCount($conditions, $recursive, $extra); } } And this is how I settup custom plain sql from controller before calling $this->paginate(); $this->paginate=array( 'limit'=>Configure::read('Page.PostCount') //my appwide limit for posts ,'conditions'=>array( 'sql' =>"my custom query")); Any thoughts? On Jan 23, 7:54 am, cricket <[email protected]> wrote: > On Sat, Jan 22, 2011 at 11:52 PM, mmamedov <[email protected]> wrote: > > OK I did it. > > Just to clarify one thing: In my example, the value of the array > that's passed for $scope is irrelevant. The important thing is to > check if the 'union' key is set in $conditions. But, if you need to > pass any data keep in mind that the array value can be another array > (possibly with many keys). So, > > $this->paginate('User', array('union' => array('foo' => 'bar'))); -- 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 [email protected] For more options, visit this group at http://groups.google.com/group/cake-php
