In this tenth episode of the CodeIgniter From Scratch screencast series, we will be exploring the Calendar library. We are also going to utilize the database class and jQuery AJAX. I will show you how to build a simple and CSS-styled calendar page, which will have the ability to store and display content for each day.
Catch Up
- Day 1: Getting Started With the Framework
- Day 2: Database Selecting Methods
- Day 3: Sending Emails
- Day 4: Newsletter Signup
- Day 5: CRUD
- Day 6: Login
- Day 7: Pagination
- Day 8: AJAX
- Day 9: File Uploading and Image Manipulation
- Day 10: The Calendar Library
Day 10: The Calendar Library
Other Viewing Options
- Follow us on Twitter, or subscribe to the Nettuts+ RSS Feed for more daily web development tuts and articles.








jQuery Lightbox Evolution only $12.00
Events Calendar Pro - Wordpr ... only $30.00 
Thanks, very useful, maybe you could make a Facebook – CodeIgniter integration or a Star Rating System using CodeIgniter tutorial.
Plz can’t you put the database of this project.
Hello
Great Job..
Looking very nice.
Better to place database script in the download.
cheers
Krishna Mohan L V
Thank you for the available link to download the mp4 file. Its hard to me to watch the video online (in slow connection), so I need to download the file then watch on my PC. Very useful tutorial for me
Great programing! What do I need to do to get more events onto 1 cell/day? Since the key is the day, the key has to be unique. What would be an elegant way to show multiple events for 1 day?
In order to pull that off in a nice way – I actually modified the calendar library a bit. The standard gives you a good bit of control – but still can be somewhat limiting. Here’s what I have come up with that shows events spanning multiple days and can also cover the same days as well.
http://ttgdev.com/marsmedia/calendar/display/2010/06
Bryan
Hey, the multiple day spanning deal on that calendar looks pretty slick, do you have any code anywhere that we can look at for that?
Sure – give me a day or 2 and I will throw it together and give you a url. Trying to finish up the whole calendar
I wouldn’t mind getting a look and taking it for a test run.
Good things happening!
This is odd, I can’t display any items for day_num values 1 to 9 … no single digit days.
I checked, the calendar events for those days are recorded in the database.
The data does appear in $cal_data being passed to $this->calendar->generate($year, $month, $cal_data);
But the resulting string does not include the calendar events for days 1 to 9.
Anyone else get this?
In the model, in function get_calendar_data, you have to strip off the leading ’0′ where applicable.
My solution:
–
function get_calendar_data($year, $month) {
$query = $this->db->select(‘date, data’)->from(‘sys_calendar’)
->like(‘date’, “$year-$month”, ‘after’)->get();
$cal_data = array();
foreach ($query->result() as $key=>$row) {
$cal_data[substr($row->date,8,2) + 0] = $row->data;
}
return $cal_data;
}
–
Adding a ’0′ in the cal_data assignment has the effect of converting the string ’01′ to the number ’1′ … solving the problem.
Hope that helps someone else.
thx a lot, this solved my problem
hope codeigniter will fix this in the next release
Or you can use phps intval() function to the substr($row->date, 8, 2);
cheers
big Thanks for the intval()!
Btw, entries would still not be removed unless accessed via a db manager like phpmyadmin (suppose you wish to delete a note by replacing it with a null value). The calendar would look empty but if you’ll scan the db, the entry is still there (with a null data value). maybe you could add a function that deletes the entry in case a null value is entered.
I changed my database structure so that I could enter multiple things for any one given date. My calendar is only displaying the most recent entry in my table. Can someone point me in the right direction as to what needs to change in the get_calendar_data function for multiple entries to display? Thanks!
I’m having a problem passing my config to the library. It just doesn’t seems to load it… anything I put in config it has no effect… any ideas what I could be doing wrong?
Thanks Burak,
Another great tutorial! I have it working perfectly in firefox/ safari but for some reason ie won’t do the post? Any ideas anyone?
I’m running Codeigniter on MAMP and IE is on windows in a Virtual Machine. Firefox in the same VM works fine.
I thought at first it might be something to do with the prompt so I created a modal to hold a form but still no dice.
I’m really stuck for ideas now so any help would be gratefully received!
Many thanks Burak, a terrific turtorial.
For those of you who dont know what to put in the ‘calendar’ table for this database, let me tell you it is very simple.
I am assuming that you are using WAMP, though this should work wherever you have phpMyAdmin installed.
Start phpMyAdmin, create a database ‘ci_series’.
Create a table ‘calendar’.
Have 2 columns: 1st named ‘date’ with type ‘DATE’
2nd named ‘data’ with type ‘VARCHAR’ and length about 100.
And then save the table.
And then just run the source code that you get from above, thanks to Burak.
Cheers,
Rishi.
@burak
Thank you very much for this very very nice tutorial.
God Bless you and Thank you!
thanks a lot….. may god bless tutplus network
the tutorial is php4 oop, i change to php 5 oop, seem like we cannot use $config word as our config variable , it generate error, must use any other than $config.
wao! waste so much time to figure wat wrong wif my code…
does it work for day which range from 1-9?
i cant get it work by entering the data, the tutorial also aim at day range from 10-31 only,
so anyone? or i make mistake?