Latest Websites

Bid Daddy Demo

The Client was looking for a basic demo for his website Bid Daddy so that he could...>>read more.

k@Khuis

Chris Koch, a long-time friend, wanted a online presence for his band k@Khuis and other projects he has going.read more.

Craft Pots

The client was looking for a forum for their group of friends to chat and share their craft projects with each other. Specificly requesting that the design be out the...>>read more.

My Blog

Web Design Strip

Development Reflection

2010 gone, I thought I would take a look back at my year and reflect a little.

2009 saw me making a lot more contacts and meeting.....
read more.

Successful Search Engine Optimisation

I was very impressed to see how effective my search engine optimised friendly urls are when I googled specific keywords on topics discussed in.....
read more.

Tutorials Index

  1. 2

  2. Smarty Functions

    1. This URL Smarty Function
  3. Smarty Pagination Plugin

    1. Pagination Class
    2. Smarty Pager Function
  4. Build a scalable website/weblog/cms

    1. Getting Started
    2. Build the Foundations
    3. Dynamic SEO Friendly URL
    4. PHP Helper Classes

Tutorials Intro

These tutorials reflect personal projects while practicing of new tools, ideas, techniques and technologies. They can not be used on their own as a final solution for any website.

I will be using xHTML, CSS and PHP in most of the tutorials so a basic understanding of each will be ideal but not a requirement if you work each tutorial from the beginning. I will also be making use of the jQuery javascript API for effects, AJAX and loads more.

My personal favourite has got to be the versatile and highly scalable php Smarty Template Engine, so almost everything I build uses it. I'm not on my own in working with and trusting the smarty template engine, there are loads of large names out there using it, Jamroom, XOOPS CMS, Movable Type, WHMCS, Serendipity, CMS Drupal to name a few, go to Smarty's Resources page for more.


Pagination Class


Tutorial:  Smarty Pagination Plugin

Skills:     php, smarty, xhtml

Goal:      Create Smarty Pagination Plugin

/lib/Pager.class.php
<?php
/*
The following are tha steps in the Pagination class
How many rows?
How many pages?
Number rows devided by entries per page, ceil() will round the number up.
What page are you looking at, $currentpage?
and lets make sure we are not trying to browse more or less than the available pages.
Using the information we have collected, lets get our pages information
Assign values to smarty variables and templates for use as smarty functions
*/

class Pager {
var $config;
var $db;
var $page;
var $pageInfo;
var $link = '';
var $smarty;
var $pagerFirst;
var $pagerNext;
var $pagerMid;
var $pagerPrevious;
var $pagerLast;

function __destruct(){}

function __construct($mode,$page,$perPage=0,$range=0,$navSet,$thisTpl){
$this->config = new Config();
$this->db = new DB();
$this->smarty = new Smarty();
$this->smarty->assign('mode',$mode);
$this->smarty->assign('thisTpl',$thisTpl);
$this->smarty->assign('navSet',$navSet);
$this->page = $this->config->page;
$page = (int)$page;
switch($mode){
case 'blog':
$table = 'news';
$order = 'news_date';
break;
}
$numRows = $this->db->countRows($table);
if($perPage==0||$perPage==''){
$perPage = $this->page['entriesPerPage'];
}
if($range==''){
$range = $this->page['range'];
}
$numPages = ceil($numRows/$perPage);

if ($page > $numPages) {
$page = $numPages;
}
if ($page < 1) {
$page = 1;
}
$offset = ($page - 1) * $perPage;
$this->pageInfo = $this->db->getPagedInfo($table,$offset,$perPage,$order);



if ($page > 1) {

$this->smarty->assign('link','1');
$first = $this->smarty->fetch('pager_first.tpl');
$this->pagerFirst = $first;
$prevPage = $page - 1;
$this->smarty->assign('link',$prevPage);
$previous = $this->smarty->fetch('pager_previous.tpl');
$link = $first.$previous;
$this->pagerPrevious = $previous;
}
$this->smarty->assign('currentpage',$page);
for ($i = ($page - $range); $i < (($page + $range) + 1); $i++) {
if($i>0 && $i<=$numPages) {
$this->smarty->assign('i',$i);
$mid = $this->smarty->fetch('pager_middle.tpl');
$link .= $mid;
$this->pagerMid .= $mid;
}
}
if ($page != $numPages) {
$nextPage = $page + 1;
$this->smarty->assign('link',$nextPage);
$next = $this->smarty->fetch('pager_next.tpl');
$this->smarty->assign('link',$numPages);
$last = $this->smarty->fetch('pager_last.tpl');
$link .= $next.$last;
$this->pagerNext = $next;
$this->pagerLast = $last;
}

$this->link = '<div id="navSet">'.$link.'</div>';

}
} ?>