Hi, I have 2 separate listings of data in a page with search function and pagination. I want the search terms to be hold when paginating.
To implement this I had used the following snippet in my controller named WorkoutController: class WorkoutsController extends AppController { var $name = 'Workouts'; var $uses = array ('Workout','WorkoutCategory','Myworkout','Workoutplanner','Workoutdetail'); var $helpers = array('Html', 'Form', 'Ajax', 'Javascript', 'Fck'); // called before every single action function beforeFilter() { // some code here } function index() { $this->layout = 'default'; //following is for myfavorite workouts $this->data['Myworkout'] = $this->_proxyGather(); $this->paginate['Myworkout']['conditions']['Myworkout.userId'] = $this->Session->read('userId'); if(!empty($this->data['Myworkout']['workoutName_myworkout'])) { $this->data['Myworkout']['workoutName'] = $this->data['Myworkout'] ['workoutName_myworkout']; $this->paginate['Myworkout']['conditions']['Myworkout.workoutName LIKE'] = '%'.$this->data['Myworkout']['workoutName'].'%'; } $this->paginate['Myworkout']['conditions']['Myworkout.status'] = 'Y'; $this->paginate['Myworkout']['limit'] = 3; $this->paginate['Myworkout']['order'] = array ('Myworkout.myworkoutId' => 'desc'); $myworkouts = $this->paginate('Myworkout'); $this->set('myworkouts', $myworkouts); // following is for predefined workouts $fitnessExperienceLevels = array('' => '-- All --', 'I' => 'inXperianced', 'E' => 'Xperianced', 'X' => 'Xpert'); $this->set(compact('fitnessExperienceLevels')); $workoutCategoryIds = $this->WorkoutCategory->find('list', array ('fields' => array('WorkoutCategory.categoryTitle'))); $this->set(compact('workoutCategoryIds')); $this->data['Workout'] = $this->_proxyGather(); if(!empty($this->data['Workout']['fitnessExperienceLevel'])) { $this->paginate['Workout']['conditions'] ['Workout.fitnessExperienceLevel'] = $this->data['Workout'] ['fitnessExperienceLevel']; } if(!empty($this->data['Workout']['workoutCategoryId'])) { $this->paginate['Workout']['conditions'] ['Workout.workoutCategoryId'] = $this->data['Workout'] ['workoutCategoryId']; } if(!empty($this->data['Workout']['workoutName_preworkout'])) { $this->data['Workout']['workoutName'] = $this->data['Workout'] ['workoutName_preworkout']; $this->paginate['Workout']['conditions']['Workout.workoutName LIKE'] = '%'.$this->data['Workout']['workoutName'].'%'; } $this->paginate['Workout']['conditions']['Workout.status'] = 'Y'; $this->paginate['Workout']['limit'] = 3; $this->paginate['Workout']['order'] = array('Workout.workoutId' => 'desc'); $predefined_workouts = $this->paginate('Workout'); $this->set('predefined_workouts', $predefined_workouts); if(isset($this->params['named']['perform'])) { if(is_numeric($this->params['named']['perform'])) { $this->Myworkout->unbindModel(array('belongsTo' => array ('User'))); $perform_array = $this->Myworkout->findByMyworkoutid($this->params ['named']['perform']); $this->set('perform_array', $perform_array); } } $planned_workouts = $this->Workoutplanner->find('all',array ('conditions' => array('Myworkout.userId' => $this->Session->read ('userId'),'Workoutplanner.created LIKE' => date("Y-m-d").'%'),'order' => array('Workoutplanner.workoutplannerId'))); $this->set('planned_workouts', $planned_workouts); } function myworkouts() { $this->layout = ''; Configure::write('debug', '0'); //following is for myfavorite workouts $this->data['Myworkout'] = $this->_proxyGather(); $this->paginate['Myworkout']['conditions']['Myworkout.userId'] = $this->Session->read('userId'); if(!empty($this->data['Myworkout']['workoutName_myworkout'])) { $this->data['Myworkout']['workoutName'] = $this->data['Myworkout'] ['workoutName_myworkout']; $this->paginate['Myworkout']['conditions']['Myworkout.workoutName LIKE'] = '%'.$this->data['Myworkout']['workoutName'].'%'; } $this->paginate['Myworkout']['conditions']['Myworkout.status'] = 'Y'; $this->paginate['Myworkout']['limit'] = 3; $this->paginate['Myworkout']['order'] = array ('Myworkout.myworkoutId' => 'desc'); $myworkouts = $this->paginate('Myworkout'); $this->set('myworkouts', $myworkouts); } function preworkouts() { $this->layout = ''; Configure::write('debug', '0'); // following is for predefined workouts $fitnessExperienceLevels = array('' => '-- All --', 'I' => 'inXperianced', 'E' => 'Xperianced', 'X' => 'Xpert'); $this->set(compact('fitnessExperienceLevels')); $workoutCategoryIds = $this->WorkoutCategory->find('list', array ('fields' => array('WorkoutCategory.categoryTitle'))); $this->set(compact('workoutCategoryIds')); $this->data['Workout'] = $this->_proxyGather(); if(!empty($this->data['Workout']['fitnessExperienceLevel'])) { $this->paginate['Workout']['conditions'] ['Workout.fitnessExperienceLevel'] = $this->data['Workout'] ['fitnessExperienceLevel']; } if(!empty($this->data['Workout']['workoutCategoryId'])) { $this->paginate['Workout']['conditions'] ['Workout.workoutCategoryId'] = $this->data['Workout'] ['workoutCategoryId']; } if(!empty($this->data['Workout']['workoutName_preworkout'])) { $this->data['Workout']['workoutName'] = $this->data['Workout'] ['workoutName_preworkout']; $this->paginate['Workout']['conditions']['Workout.workoutName LIKE'] = '%'.$this->data['Workout']['workoutName_preworkout'].'%'; } $this->paginate['Workout']['conditions']['Workout.status'] = 'Y'; $this->paginate['Workout']['limit'] = 3; $this->paginate['Workout']['order'] = array('Workout.workoutId' => 'desc'); $predefined_workouts = $this->paginate('Workout'); $this->set('predefined_workouts', $predefined_workouts); } } And following in the view for pagination: //for first listing ============ <table> <tr> <?php echo $paginator->options(array('update' => 'myworkout_content', 'url' => array('controller' => 'workouts', 'action' => 'myworkouts'))); //echo $paginator->options(array('url' => $this->passedArgs)); ?> <td><?php echo $paginator->prev('Previous ', array('class' => 'blue_link_11px'), null, array('class' => 'disabled'));?></td> <td align="center"><?php echo $paginator- >counter(); ?></td> <td><?php echo $paginator->next(' Next', array ('class' => 'blue_link_11px'), null, array('class' => 'disabled')); ? ></td> </tr> </table> //for 2nd listing =========== <table> <tr> <?php echo $paginator->options(array('update' => 'preworkout_content', 'url' => array('controller' => 'workouts', 'action' => 'preworkouts'))); //echo $paginator->options(array('url' => $this->passedArgs)); ?> <td><?php echo $paginator->prev('Previous ', array('class' => 'blue_link_11px'), null, array('class' => 'disabled'));?></td> <td align="center"><?php echo $paginator- >counter(); ?></td> <td><?php echo $paginator->next(' Next', array('class' => 'blue_link_11px'), null, array('class' => 'disabled')); ?></td> </tr> </table> But as a result the pagination is not working well. When I am searching on the first listing the pagination is getting same for both listing, although I have different numbers of data in both the listings. Please help about this matter. Thanks, Subhadeep --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---