Skip to content

Instantly share code, notes, and snippets.

@takuma7
Forked from slywalker/pagination.ctp
Created August 28, 2012 02:53
Show Gist options
  • Select an option

  • Save takuma7/3494513 to your computer and use it in GitHub Desktop.

Select an option

Save takuma7/3494513 to your computer and use it in GitHub Desktop.

Revisions

  1. takuma7 revised this gist Aug 29, 2012. 1 changed file with 40 additions and 40 deletions.
    80 changes: 40 additions & 40 deletions pagination.ctp
    Original file line number Diff line number Diff line change
    @@ -1,40 +1,40 @@
    <?php
    /*
    * pagination number element for CakePHP ON TWITTER BOOTSTRAP!
    * created by TaKUMA7
    * 28 Aug. 2012
    */
    echo $this->Paginator->prev('«',
    array(
    'tag' => 'li',
    'class' => 'prev',
    ),
    $this->Paginator->link('«', array()),
    array(
    'tag' => 'li',
    'escape' => false,
    'class' => 'prev disabled',
    )
    );
    echo preg_replace(
    '/<li class="active">(\d+)<\/li>/',
    '<li class="active"><a href="#">$1</a></li>',
    $this->Paginator->numbers(array(
    'tag' => 'li',
    'currentClass' => 'active',
    'separator' => null,
    ))
    );
    echo $this->Paginator->next('»',
    array(
    'tag' => 'li',
    'class' => 'next',
    ),
    $this->Paginator->link('»', array()),
    array(
    'tag' => 'li',
    'escape' => false,
    'class' => 'next disabled',
    )
    );
    ?>
    <div class="pagination">
    <ul>
    <?php
    echo $this->Paginator->prev('«',
    array(
    'tag' => 'li',
    'class' => 'prev',
    ),
    $this->Paginator->link('«', array()),
    array(
    'tag' => 'li',
    'escape' => false,
    'class' => 'prev disabled',
    )
    );

    echo preg_replace(
    '/<li class="active">(\d+)<\/li>/',
    '<li class="active"><a href="#">$1</a></li>',
    $this->Paginator->numbers(array(
    'tag' => 'li',
    'currentClass' => 'active',
    'separator' => null,
    ))
    );
    echo $this->Paginator->next('»',
    array(
    'tag' => 'li',
    'class' => 'next',
    ),
    $this->Paginator->link('»', array()),
    array(
    'tag' => 'li',
    'escape' => false,
    'class' => 'next disabled',
    )
    );
    ?>
    </ul>
    </div>
  2. takuma7 revised this gist Aug 28, 2012. 1 changed file with 39 additions and 61 deletions.
    100 changes: 39 additions & 61 deletions pagination.ctp
    Original file line number Diff line number Diff line change
    @@ -1,62 +1,40 @@
    <?php
    if (!isset($modules)) {
    $modulus = 11;
    }
    if (!isset($model)) {
    $models = ClassRegistry::keys();
    $model = Inflector::camelize(current($models));
    }
    ?>
    <div class="pagination">
    <ul>
    <?php echo $this->Paginator->first('<<', array('tag' => 'li')); ?>
    <?php echo $this->Paginator->prev('<', array(
    'tag' => 'li',
    'class' => 'prev',
    ), $this->Paginator->link('<', array()), array(
    'tag' => 'li',
    'escape' => false,
    'class' => 'prev disabled',
    )); ?>
    <?php
    $page = $this->params['paging'][$model]['page'];
    $pageCount = $this->params['paging'][$model]['pageCount'];
    if ($modulus > $pageCount) {
    $modulus = $pageCount;
    }
    $start = $page - intval($modulus / 2);
    if ($start < 1) {
    $start = 1;
    }
    $end = $start + $modulus;
    if ($end > $pageCount) {
    $end = $pageCount + 1;
    $start = $end - $modulus;
    }
    for ($i = $start; $i < $end; $i++) {
    $url = array('page' => $i);
    $class = null;
    if ($i == $page) {
    $url = array();
    $class = 'active';
    }
    echo $this->Html->tag('li', $this->Paginator->link($i, $url), array(
    'class' => $class,
    ));
    }
    ?>
    <?php echo $this->Paginator->next('>', array(
    'tag' => 'li',
    'class' => 'next',
    ), $this->Paginator->link('>', array()), array(
    'tag' => 'li',
    'escape' => false,
    'class' => 'next disabled',
    )); ?>
    <?php echo str_replace('<>', '', $this->Html->tag('li', $this->Paginator->last('>>', array(
    'tag' => null,
    )), array(
    'class' => 'next',
    ))); ?>
    </ul>
    </div>
    /*
    * pagination number element for CakePHP ON TWITTER BOOTSTRAP!
    * created by TaKUMA7
    * 28 Aug. 2012
    */
    echo $this->Paginator->prev('«',
    array(
    'tag' => 'li',
    'class' => 'prev',
    ),
    $this->Paginator->link('«', array()),
    array(
    'tag' => 'li',
    'escape' => false,
    'class' => 'prev disabled',
    )
    );
    echo preg_replace(
    '/<li class="active">(\d+)<\/li>/',
    '<li class="active"><a href="#">$1</a></li>',
    $this->Paginator->numbers(array(
    'tag' => 'li',
    'currentClass' => 'active',
    'separator' => null,
    ))
    );
    echo $this->Paginator->next('»',
    array(
    'tag' => 'li',
    'class' => 'next',
    ),
    $this->Paginator->link('»', array()),
    array(
    'tag' => 'li',
    'escape' => false,
    'class' => 'next disabled',
    )
    );
    ?>
  3. @slywalker slywalker revised this gist Oct 7, 2011. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion pagination.ctp
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,9 @@ if (!isset($model)) {
    <?php echo $this->Paginator->first('<<', array('tag' => 'li')); ?>
    <?php echo $this->Paginator->prev('<', array(
    'tag' => 'li',
    'class' => 'prev',
    ), $this->Paginator->link('<', array()), array(
    'tag' => 'li',
    'escape' => false,
    'class' => 'prev disabled',
    )); ?>
    @@ -45,10 +47,16 @@ if (!isset($model)) {
    ?>
    <?php echo $this->Paginator->next('>', array(
    'tag' => 'li',
    'class' => 'next',
    ), $this->Paginator->link('>', array()), array(
    'tag' => 'li',
    'escape' => false,
    'class' => 'next disabled',
    )); ?>
    <?php echo $this->Paginator->last('>>', array('tag' => 'li')); ?>
    <?php echo str_replace('<>', '', $this->Html->tag('li', $this->Paginator->last('>>', array(
    'tag' => null,
    )), array(
    'class' => 'next',
    ))); ?>
    </ul>
    </div>
  4. @slywalker slywalker renamed this gist Oct 5, 2011. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. @slywalker slywalker created this gist Oct 5, 2011.
    54 changes: 54 additions & 0 deletions pasination.ctp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    <?php
    if (!isset($modules)) {
    $modulus = 11;
    }
    if (!isset($model)) {
    $models = ClassRegistry::keys();
    $model = Inflector::camelize(current($models));
    }
    ?>
    <div class="pagination">
    <ul>
    <?php echo $this->Paginator->first('<<', array('tag' => 'li')); ?>
    <?php echo $this->Paginator->prev('<', array(
    'tag' => 'li',
    ), $this->Paginator->link('<', array()), array(
    'escape' => false,
    'class' => 'prev disabled',
    )); ?>
    <?php
    $page = $this->params['paging'][$model]['page'];
    $pageCount = $this->params['paging'][$model]['pageCount'];
    if ($modulus > $pageCount) {
    $modulus = $pageCount;
    }
    $start = $page - intval($modulus / 2);
    if ($start < 1) {
    $start = 1;
    }
    $end = $start + $modulus;
    if ($end > $pageCount) {
    $end = $pageCount + 1;
    $start = $end - $modulus;
    }
    for ($i = $start; $i < $end; $i++) {
    $url = array('page' => $i);
    $class = null;
    if ($i == $page) {
    $url = array();
    $class = 'active';
    }
    echo $this->Html->tag('li', $this->Paginator->link($i, $url), array(
    'class' => $class,
    ));
    }
    ?>
    <?php echo $this->Paginator->next('>', array(
    'tag' => 'li',
    ), $this->Paginator->link('>', array()), array(
    'escape' => false,
    'class' => 'next disabled',
    )); ?>
    <?php echo $this->Paginator->last('>>', array('tag' => 'li')); ?>
    </ul>
    </div>