1

Following is the PHP code of a smarty plugin to apply pagination to the pages.

<?php

function smarty_function_pagination_link_01($params, &$smarty)
{

    if ( !is_array($params['values']) )
    {
      return "is not array";
    }
    if ( 0 == count($params['values']) )
    {
      return "Empty Array";
    }
    if ( empty($params['values']['current_page']) )
    {
      return "Invalid Request";
    }

    $values = $params['values'];

    //Seperator Used Betwinn Pagination Links
    $seprator = empty( $params['seperator'] ) ? "&nbsp;&nbsp;" : $params['seperator'];

    //Class Name For Links
    $extra = empty( $params['extra'] ) ? "" : $params['extra'];

    $current_page  = (int)$values['current_page'];

    if ( !empty($values['first']) )
    {
        //$ret[] = "<a $extra href='{$values['first']}' >&lt;First</a>";
    }
    if ( !empty($values['previous'] ) )
    {
        $ret[] = "<a $extra href='{$values['previous']}' class='prev active'><span></span></a>";                
    }
    $ret[] = "<ul>";
    foreach( $values as $k => $v )
    {
          if( is_numeric( $k ) )
          {
                if ( $k == $current_page)
                {
                    $ret[] = "<li><a $extra class='active'>$k</a></li>";
                }
                else
                {

                    $ret[] = "<li><a $extra href='$v'>$k </a></li>";

                }
          }
    }

    if ( !empty($values['next'] ) )
    {
        $ret[] = "</ul><a $extra href='{$values['next']}' class='next active'><span></span></a>";

    }

    if ( !empty($values['last'] ) )
    {
        //$ret[] = "<a $extra href='{$values['last']}' >Last&gt;</a>";
    }

    //$str_ret = $first . $previous . $str_ret . $next . $last;
    if ( $ret )
    {
        return implode( $seprator, $ret );
    }
}
?>

This function is called from the smarty template. Now it's working perfectly. But I want to change the behavious of above function, I want to change the value it is returning. The value of the argument $params the above function is getting is as follows:

Array
(
    [values] => Array
        (
            [1] => /xyz/pqr/web/control/modules/questions/view_questions.php?subject_id=&topic_id=&difficulty_level=&from_date=01/02/1999&to_date=17/02/2014&staff_id=&page=1
            [2] => /xyz/pqr/web/control/modules/questions/view_questions.php?subject_id=&topic_id=&difficulty_level=&from_date=01/02/1999&to_date=17/02/2014&staff_id=&page=2
            [3] => /xyz/pqr/web/control/modules/questions/view_questions.php?subject_id=&topic_id=&difficulty_level=&from_date=01/02/1999&to_date=17/02/2014&staff_id=&page=3
            [next] => /xyz/pqr/web/control/modules/questions/view_questions.php?subject_id=&topic_id=&difficulty_level=&from_date=01/02/1999&to_date=17/02/2014&staff_id=&page=2
            [last] => /xyz/pqr/web/control/modules/questions/view_questions.php?subject_id=&topic_id=&difficulty_level=&from_date=01/02/1999&to_date=17/02/2014&staff_id=&page=8170
            [current_page] => 1
        )

)

Now the display of the page numbers are is as follows: ![enter image description here][1]

But I want the opagination numbers in the following fashion:

1 2 3 4 5 6 7 8 9 10 Next Last

How should I get the above pattern by making changes into the function?Thanks in advance.

1 Answers1

0

Try to configure it with num_links like

$config['num_links'] = 10;
GautamD31
  • 28,552
  • 10
  • 64
  • 85