I believe it is because you put the condition ino paginate but you haven't rewrited the count method. There is an example of this in the cook book , I think the link is this one : http://book.cakephp.org/view/1237/Custom-Query-Pagination .
There is one important notice for you here. I had an issue where I needed two diffrent paginations for the same model element, and the problem is, you can rewrite the count function only for one (because you rewrite it to meet your condition). The problem is , how to make count function for multiple conditions such as, show me only published posts, or show all posts if I am logged in as admin in order to publish some posts. Those are 2 different paginations, but I can have only one count function. The solution to this is to make a global variable (i tried to pass an argument to the rewrited count function, but it didn't work for some reason, it may be my mistake) and set it each time before you call your pagination. You put an if clause in the count function, and then if condition one is true, then you return one count value based on that condition (e.g number of all published posts), and if the condition two is true then you return some other value for the count (e.g. I am a administrator, I should see all of the posts, so for the count of pagination my view needs to get the total number of all posts). Hope it helps On Sep 2, 5:24 pm, Michael Gaiser <mjgai...@gmail.com> wrote: > So, I have been trying to get this paginate feature working and I can get > the first page properly, but when it returns the 2nd page, the query is > empty. Anyone see anything wrong? I suspect it has something to do with the > $searchStr arg but am unsure how to get around not having an arg in that > function. Thanks. > > ~Michael > > function index($searchStr = null) { > $results = array(); > > //Use the searchStr if there is no data. > if(empty($this->data) && $searchStr != null) { > $this->data['autoComplete'] = $searchStr; > $this->data['Location']['constrainType'] = -1; > } > > if (!empty($this->data)) { > $autoCompleteStr = ''; > if($this->data['autoComplete'] != '**') { > $autoCompleteStr = $this->data['autoComplete']; > } > > $locationType = $this->data['Location']['constrainType'] - 1; > if ($locationType < 0) $locationType = "%"; > > $this->paginate = array( > 'limit'=>10, > 'contain' =>array('ParentLocation.name', > 'ParentLocation.type', 'ParentLocation.id', 'ConfirmedUser.username'), > 'fields'=>array('Location.id', 'Location.name', > 'Location.type', 'Location.parent_id', 'Location.longitude', > 'Location.latitude', 'Location.confirmed_id'), > 'order'=>array('Location.name ASC') > ); > $searchOptions = array('Location.name LIKE' => > $autoCompleteStr.'%', 'Location.type' => $locationType); > > switch($this->data['Location']['adminConstrainType']){ > case 0: > default: > break; > > case 1: > //Non Confirmed > $adminCondition = array('Location.confirmed_id' => > null); > $searchOptions = array_merge($searchOptions, > $adminCondition); > break; > > case 2: > //Confirmed > $adminCondition = array('Location.confirmed_id <>' => > null); > $searchOptions = array_merge($searchOptions, > $adminCondition); > break; > } > $results = $this->paginate('Location', $searchOptions); > > $this->set('locations', $results); > debug($results); > } > $this->set('constrainTypes', $this->__getConstrainTypes()); > $this->set('autocomplete', $this->data['autoComplete']); > $this->set('adminContrainTypes', $this->__getAdminContrainTypes()); > } Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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