Monday, August 30, 2010

Re: Routes / Pagination

Dave,

iIs an ugly hack in the view but works for me on http://www.unionofsports.com/brand/burton/7 :

routes.php
Router::connect('/brand/:manufacturer_slug', array('controller'=> 'products', 'action' => 'brand'), array('pass' => array('manufacturer_slug')));
Router::connect('/brand/:manufacturer_slug/:page', array('controller'=> 'products', 'action' => 'brand'), array('pass' => array('manufacturer_slug', 'page'), 'page' => '[0-9]+'));


controller:

// for debug:
// var_dump($this->params['page']);
// var_dump($this->params['manufacturer_slug']);

   $this->paginate = array(
'recursive' => -1,
'conditions' => = array('Product.manufacturer_slug' => $this->params['manufacturer_slug']),
'order' => array('Product.price' => 'ASC', 'Product.manufacturer' => 'ASC'),
'fields' => array('Product.advertisercategory', 'Product.manufacturer', 'Product.title', 'Product.name_slug', 'Product.price', 'Product.local_image'),
'limit' => 100,
   );
   $products = $this->paginate();
   $this->set(compact('products'));


view: (removing "page:2")

  <?php $options = array('url'=> array('controller' => 'products', 'action' => 'brand', $manufacturer_slug)); ?>
  <?php $paginator->options($options); ?>
  <?php $prev_link = str_replace('page:', '', $paginator->prev('Previous Page')); ?>
  <?php $prev_link = preg_replace('/\/1"/', '"', $prev_link); ?>
  <?php echo $prev_link; ?> |
  <?php echo str_replace('page:', '', $this->Paginator->numbers());?> |
  <?php //echo $this->Paginator->numbers();?> | 
  <?php $next_link = str_replace('page:', '', $paginator->next('Next Page')); ?>
  <?php echo $next_link; ?>


:)

Andras Kende



On Aug 30, 2010, at 12:07 PM, Dave Maharaj wrote:

2 questions I cant seem to figure out
 
I was wondering how to remove  index/page:2 from the url => [controller]/index/page:2 so it looks like [controller]/2
 
And then is it possible to make pagination like that on the pirate bay where the url look like [controller']/0/99/0 where I am assuming page 0 / ending on record 99 / starting on record 0 ?
 
Ideas?
 
Thanks
 
Dave
 

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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: