Skip to content
Derek Jones edited this page Jul 5, 2012 · 3 revisions

Category:Libraries::Other

This time I'd like to add a new class called BBQQ calendar to library. I know that there is a calendar class for CodeIgniter, but this will show you how simple is to add a third party php class to CI.

Files

Download a zip file from http://www.phpclasses.org/browse/package/5743.html#download. You need to register and sign-in in order to see a download link. Unzip it somewhere in your desktop. Open calendar.php and replace <?php with the following code at the top and save it as BBQQ_Calendar.php in application/libraries/ directory. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

Controller

Copy, paste the following code and save it as calendar.php in controllers directory.

<?php class calendar extends Controller {
function __construct() {
    parent::__construct();
    $this->load->library('BBQQ_Calendar');
}

function index()
{
    
    $this->load->view('calendar_view');
}    

}

View

Copy, paste the following code and save it as calendar_view.php in views directory. Please note that I added <base href="<?=base_url();?>" /> in head section. This allows us to link a css (and javascript if you are using) file with <link href="css/example.css" media="screen" rel="stylesheet" type="text/css" > <html> <head> <title>BBQQ CALENDAR</title> <base href="<?=base_url();?>" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" > <link href="css/example.css" media="screen" rel="stylesheet" type="text/css" > <body>

A plain calendar with all default settings

<?php $cal = new BBQQ_Calendar(); $cal->render(0); ?>

A plain calenar with raw output, for geektool

<?php
$cal->render(0, 1);
?>

Customised Week Day Titles

change sun/sat to sunday/saturday

<?php $cal->setWeekDayTitle(array( 'sun' => 'Sunday', 'sat' => 'Saturday' )); $cal->render(0); ?>

Customised header

<?php $cal->render(0, 0, 'simple calendar' . ' s m t w t f s ' ); ?>

Hightlight Days With Customised Templates (Advanced Usage)

<?php $days = array( // custom template for today $cal->getToday('j') => array( 'template' => 'TODAY: :num' ), // highlight day: 5 with custom template/scripts and wrapper tag 5 => array( 'template' => ':num', 'wrapper' => array( 'tag' => 'td', 'id' => null, 'class' => 'cal-thu', 'format' => 'j F, Y', 'style' => 'color:red;background:yellow', 'onclick' => "alert('Title: ' + this.title);return false;", 'title' => ':title' ) ), // highlight day: 12 with custom template and wrapper tag 12 => array( 'template' => ':num', 'wrapper' => array( 'tag' => 'td', 'id' => null, 'class' => 'cal-thu', 'format' => 'j F, Y', 'style' => 'color:red;background:green', 'title' => 'some :title' ) ) );

$cal->highlightDays($days); $cal->render(0); ?> </body> </html>

CSS

Create a css folder as the same level as sytem, application and img folder. Find a file called example.css in the unzipped folder. Move this file to css folder.

Results

BBQQ-CALENDAR

http://www.okadadesign.no/blog/?p=340

Clone this wiki locally