I've done this a while back. It probably isn't the best way, but it works.
I'm not sure if this was done with the most recent alpha, but it's easy to
recreate: just remove the code that's used to run the findAll query and make
it use the one you supply.

cake/app_controller.php
------------------------------------
  function paginateResultSet($object = null, $results)
  {

      if (is_array($object)) {
          $whitelist = $scope;
          $scope = $object;
          $object = null;
      }

      if (is_string($object)) {
          if (isset($this->{$object})) {
              $object = $this->{$object};
          } elseif (isset($this->{$this->modelClass}) &&
isset($this->{$this->modelClass}->{$object})) {
              $object = $this->{$this->modelClass}->{$object};
          } elseif (!empty($this->uses)) {
              for ($i = 0; $i < count($this->uses); $i++) {
                  $model = $this->uses[$i];
                  if (isset($this->{$model}->{$object})) {
                      $object = $this->{$model}->{$object};
                      break;
                  }
              }
          }
      } elseif (empty($object) || $object == null) {
          if (isset($this->{$this->modelClass})) {
              $object = $this->{$this->modelClass};
          } else {
              $object = $this->{$this->uses[0]};
          }
      }

      if (!is_object($object)) {
          // Error: can't find object
          return array();
      }
      $options = am($this->params, $this->params['url'], $this->passedArgs);

      if (isset($this->paginate[$object->name])) {
          $defaults = $this->paginate[$object->name];
      } else {
          $defaults = $this->paginate;
      }

      if (isset($options['show'])) {
          $options['limit'] = $options['show'];
      }

      if (isset($options['sort']) && isset($options['direction'])) {
          $options['order'] = array($options['sort'] =>
$options['direction']);
      } elseif (isset($options['sort'])) {
          $options['order'] = array($options['sort'] => 'asc');
      }

      if (!empty($options['order']) && is_array($options['order'])) {
          $key = key($options['order']);
          if (strpos($key, '.') === false && $object->hasField($key)) {
              $options['order'][$object->name . '.' . $key] =
$options['order'][$key];
              unset($options['order'][$key]);
          }
      }

      $vars = array('fields', 'order', 'limit', 'page', 'recursive');
      $keys = array_keys($options);
      $count = count($keys);

      for($i = 0; $i < $count; $i++) {
          if (!in_array($keys[$i], $vars)) {
              unset($options[$keys[$i]]);
          }
          if (empty($whitelist) && ($keys[$i] == 'fields' || $keys[$i] ==
'recursive')) {
              unset($options[$keys[$i]]);
          } elseif (!empty($whitelist) && !in_array($keys[$i], $whitelist))
{
              unset($options[$keys[$i]]);
          }
      }

      $conditions = $fields = $order = $limit = $page = $recursive = null;
      if (!isset($defaults['conditions'])) {
          $defaults['conditions'] = array();
      }

      extract($options = am(array('page' => 1, 'limit' => 20), $defaults,
$options));
          /*if (is_array($scope) && !empty($scope)) {
          $conditions = am($conditions, $scope);
      } elseif (is_string($scope)) {
          $conditions = array($conditions, $scope);
      }
          $recursive = $object->recursive;
      */
      $count = $object->findCount($conditions, $recursive);
      $pageCount = ceil($count / $limit);

      if($page == 'last') {
          $options['page'] = $page = $pageCount;
      }

      //$results = $object->findAll($conditions, $fields, $order, $limit,
$page, $recursive);
      $paging = array(
          'page'        => $page,
          'current'    => count($results),
          'count'        => $count,
          'prevPage'    => ($page > 1),
          'nextPage'    => ($count > ($page * $limit)),
          'pageCount'    => $pageCount,
          'defaults'    => am(array('limit' => 20, 'step' => 1), $defaults),

          'options'    => $options
      );

      $this->params['paging'][$object->name] = $paging;

      if (!in_array('Paginator', $this->helpers) &&
!array_key_exists('Paginator', $this->helpers)) {
          $this->helpers[] = 'Paginator';
      }

      return $results;
  }
------------------------------------

Arjen

On 8/1/07, Ketan Patel <[EMAIL PROTECTED]> wrote:
>
>
> You will have to overload the paginate method in your model. And then
> in the model you could write your custom queries as required. Read the
> code for more information.
>
> Ketan.
>
> kionae wrote:
> > Is there any way to just pass an array into 1.2's paginate function
> > and have it paginate the data?  Essentially, I have an array that is a
> > set of search results returned by some custom queries and a bit of
> > manipulation.  I couldn't generate the results I needed by going
> > through $this->paginate because it wouldn't let me join tables, so I'm
> > stuck with using the custom queries.
> >
> > I've seen other topics on this, but there didn't seem to be a clear
> > answer (in fact I'm still not even sure this is possible after reading
> > them all).
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to