Re: Paginate page 2+ not working
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 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
Re: Paginate page 2+ not working
On Thu, Sep 2, 2010 at 8:53 PM, Michael Gaiser wrote: > With a little poking around I think I have found the true issue here. When > you click on a paginate link, it appends 'page:2' or whatever page it is > going to to your url and then internally uses the previously saved query to > get the next set of records. But 'page:2' is not passed in as an argument or > at least I am not able to capture it to test if a paginate query is being > performed or if this is the first time I am loading the page and nothing has > been asked for yet. So my question is this. How do I know if a paginate > query is being performed as opposed to the page loading for the first time. debug($this->params); You should see: Array ( [pass] => Array ( ) [named] => Array ( [page] => 2 ) etc. 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
Re: Paginate page 2+ not working
With a little poking around I think I have found the true issue here. When you click on a paginate link, it appends 'page:2' or whatever page it is going to to your url and then internally uses the previously saved query to get the next set of records. But 'page:2' is not passed in as an argument or at least I am not able to capture it to test if a paginate query is being performed or if this is the first time I am loading the page and nothing has been asked for yet. So my question is this. How do I know if a paginate query is being performed as opposed to the page loading for the first time. ~Michael On Thu, Sep 2, 2010 at 5:37 PM, Michael Gaiser wrote: > I was meaning $results didnt have any info in it. When I debug($results), > it is just an empty array. I think this has something to do with the fact > that the paginate link doesnt supply the views form again, so some of the > info I am looking for before doing the query doesnt exist the 2nd time > around. > > ~Michael > > > On Thu, Sep 2, 2010 at 10:30 AM, cricket wrote: > >> When you say that the query is empty, do you mean $results? Or are you >> referring to the DB query itself (as printed at the bottom of the >> page, for example)? >> >> Have you tried debugging $searchOptions immediately after the switch >> block? Perhaps also debug $this->data at the beginning of the action. >> >> On Thu, Sep 2, 2010 at 11:24 AM, Michael Gaiser >> 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.comFor >> > more options, visit this group at >> > http://groups.google.com/group/cake-php?hl=en >> > >> >> 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 su
Re: Paginate page 2+ not working
I was meaning $results didnt have any info in it. When I debug($results), it is just an empty array. I think this has something to do with the fact that the paginate link doesnt supply the views form again, so some of the info I am looking for before doing the query doesnt exist the 2nd time around. ~Michael On Thu, Sep 2, 2010 at 10:30 AM, cricket wrote: > When you say that the query is empty, do you mean $results? Or are you > referring to the DB query itself (as printed at the bottom of the > page, for example)? > > Have you tried debugging $searchOptions immediately after the switch > block? Perhaps also debug $this->data at the beginning of the action. > > On Thu, Sep 2, 2010 at 11:24 AM, Michael Gaiser > 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.comFor > > more options, visit this group at > > http://groups.google.com/group/cake-php?hl=en > > > > 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.comFor > more options, visit this group at > http://groups.google.com/group/cake-php?hl=en > 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
Re: Paginate page 2+ not working
When you say that the query is empty, do you mean $results? Or are you referring to the DB query itself (as printed at the bottom of the page, for example)? Have you tried debugging $searchOptions immediately after the switch block? Perhaps also debug $this->data at the beginning of the action. On Thu, Sep 2, 2010 at 11:24 AM, Michael Gaiser 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 > 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
Paginate page 2+ not working
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