This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » support » General discussion » preg_match in PaginationHelper
preg_match in PaginationHelper [message #97091] Sat, 10 April 2010 17:06 Go to next message
janismucenieks  is currently offline janismucenieks
Messages: 31
Registered: March 2010
Location: Latvia
Member
Hello!

Using great tutorials and code snippets got my self nice pagination working. Everything works great using address bar. But I'm having trouble getting PaginationHelper to produce working uri.

The working (one that can be used straigt in addressbar) uri look like this:
/car/index/page/2

But PagginationHellper makes them this way:
/car?/index/page=2


in indexSuccess.php I have this line:
<?php  echo pager_navigation($pager, 'car/index/') ?>


and pagginationHelper.php looks like this:
function pager_navigation($pager, $uri)
{
  $navigation = '';
 
  if ($pager->haveToPaginate())
  {  
    $uri .= (preg_match('/\?/', $uri) ? '&' : '?').'/index/page=';
 
    // First and previous page
    if ($pager->getPage() != 1)
    {
      $navigation .= link_to(image_tag('/sf/sf_admin/images/first.png', 'align=absmiddle'), $uri.'1');
      $navigation .= link_to(image_tag('/sf/sf_admin/images/previous.png', 'align=absmiddle'), $uri.$pager->getPreviousPage()).' ';
    }
 
    // Pages one by one
    $links = array();
    foreach ($pager->getLinks() as $page)
    {
      $links[] = link_to_unless($page == $pager->getPage(), $page, $uri.$page);
    }
    $navigation .= join('  ', $links);
 
    // Next and last page
    if ($pager->getPage() != $pager->getLastPage())
    {
      $navigation .= ' '.link_to(image_tag('/sf/sf_admin/images/next.png', 'align=absmiddle'), $uri.$pager->getNextPage());
      $navigation .= link_to(image_tag('/sf/sf_admin/images/last.png', 'align=absmiddle'), $uri.$pager->getLastPage());
    }
 
  }
 
  return $navigation;
}


I think the problem is in PaginationHelper line:
$uri .= (preg_match('/\?/', $uri) ? '' : '?').'/index/page=';

Please help!
Thank You!
Janis

[Updated on: Sat, 10 April 2010 17:17]

Re: preg_match in PaginationHelper [message #97100 is a reply to message #97091 ] Sat, 10 April 2010 21:00 Go to previous messageGo to next message
janismucenieks  is currently offline janismucenieks
Messages: 31
Registered: March 2010
Location: Latvia
Member
Now it looks like it's something to do with link_to function.

If I make
$uri = "127.0.0.1:8080/frontend_dev.php/car/index/page/";

$navigation = link_to(image_tag('/sf/sf_admin/images/previous.png', 'align=absmiddle'), $uri.'1');


I get: 127.0.0.1:8080/frontend_dev.php/car/index/page/1

But if I make it
$uri = "car/index/page/";

$navigation = link_to(image_tag('/sf/sf_admin/images/previous.png', 'align=absmiddle'), $uri.'1');


I get: 127.0.0.1:8080/frontend_dev.php/car/
Re: preg_match in PaginationHelper [message #97101 is a reply to message #97100 ] Sat, 10 April 2010 21:19 Go to previous message
janismucenieks  is currently offline janismucenieks
Messages: 31
Registered: March 2010
Location: Latvia
Member
Ok I now have it working. Don't know where was the problem, but the correct way for it to work is this:

in indexSuccess.php
<?php  echo pager_navigation($pager, 'car/index') ?>


and in PaginationHelper.php
<?php
 
function pager_navigation($pager, $uri)
{
  $navigation = '';
 
  if ($pager->haveToPaginate())
  {  
    $uri .= (preg_match('/\?/', $uri) ? '&' : '?').'page=';
 
    // First and previous page
    if ($pager->getPage() != 1)
    {
      $navigation .= link_to(image_tag('/sf/sf_admin/images/first.png', 'align=absmiddle'), $uri.'1');
      $navigation .= link_to(image_tag('/sf/sf_admin/images/previous.png', 'align=absmiddle'), $uri.$pager->getPreviousPage()).' ';
    }
 
    // Pages one by one
    $links = array();
    foreach ($pager->getLinks() as $page)
    {
      $links[] = link_to_unless($page == $pager->getPage(), $page, $uri.$page);
    }
    $navigation .= join('  ', $links);
 
    // Next and last page
    if ($pager->getPage() != $pager->getLastPage())
    {
      $navigation .= ' '.link_to(image_tag('/sf/sf_admin/images/next.png', 'align=absmiddle'), $uri.$pager->getNextPage());
      $navigation .= link_to(image_tag('/sf/sf_admin/images/last.png', 'align=absmiddle'), $uri.$pager->getLastPage());
    }
 
  }
 
  return $navigation;
}

Just like in tutorial here: http://trac.symfony-project.org/wiki/sfDoctrinePager
Previous Topic:Cache: avoid creation of one cache file per subdomain
Next Topic:Need simple sample for doctrine
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software