A recent project required an event calendar in both a mini and full sized format. The project was based on Zend Framework, a highly scalable and feature-rich PHP MVC framework. The resulting Calendar class is admittedly quite basic, but I thought it might prove useful for other PHP/Zend coders who are trying to find a simple yet extensible Calendar solution for their own projects.
Localization
The benefit of using Zend_Date is that it relies on Zend_Locale for localization. To promote this, this custom Calendar class can be used to create a calendar in any language via the class constructor’s ‘locale’ parameter.
Features
- It can output HTML in the form of a table with the month, days of the week, and days visible.
- It can generate the calendar HTML header alone, or the calendar HTML table body alone.
- It can also be used to generate previous and next month links in the case you wanted to allow users to select the month themselves.
- There is control over the table css, select box css , and select box form name via the html methods parameters
- The class can also be used to generate Calendar data that you can access via more standard (get and set) methods to support your own unique Calendaring needs, i.e. without relying on HTML output.
Demo
Here is a link to a demo to get you started.
Downloads
- Download the code here: [Download not found]
- Comment below and let me know if it met your needs!
Source/Contribute
A View Helper version is being developed:
Project source: zfcalendar project hosting

Hi
I had seen this calender this is amazing….
But i wanna three calender on one page some like
January — February — March On one page with next and previous link
Among other things, this class allows you to generate the entire Calendar HTML (getCalendarHtml), the calendar HTML header alone (getCalendarHeaderHtml ) or the calendar HTML body alone (getCalendarBodyHtml).
The simplest way would be to create your own method that would use three calendar objects (returning just the calendar body), coupled with your own implementation of the calendar header (using the non-html generating class methods alone). Of course, this isn’t the most elegant solution, but it would work in theory.
Thank you very much
You save me a lot of work.
I use it in my application with minimum of modifications.
hi this calander is good, but i see 32 days in a month?? please help
@Sandeep. I identified and fixed the extra day issue. Download the latest version.
Derek,
This is awesome. Thanks a lot for making it. First thing I added was a __toString overload
public function __toString()
{
return $this->getCalendarHtml();
}
so you can do
@Ben. Good idea! Should have done that myself!
Hi Derek,
First of all thanks for the effort
Second, I’m new to ZF and I want to use the calender.
where should I place the Calendar class and the demo code within the ZF project folders, in order to make it work on my website?
Many Thanks,
Oran
@Oran. You can put the Calendar class anywhere you like! Just make sure its part of your include path. Typically, zend framework components are stored in the ‘/library/Zend’ folder, with the include path set to ‘library’.
ex: set_include_path(get_include_path() . PATH_SEPARATOR . ‘/path/to/Zend’);
I would suggest you put the Calendar class inside the ‘library’ folder as well, either on its own, or in another folder called ‘Custom’. If you go the first route, include it in your php files using require_once ‘Calendar.php’; . In the second example use, require_once ‘Custom/Calendar.php’;
Nice job. However, there are some notices poping up. I found the issues, here are they:
1 – line 176. “$html .= “, just remove the “.”, as the $html is being created now.
2 – You call $this->localeStr, but did not declare it. Just add “private $localeStr;” at the beginning of the class together with the other properties.
3 – Do not use “onclick” for a select form element. Use “onchange” instead, or it will submit before the user is able to choose the option.
That’s all for now. Good work.
@Jaime Neto Thanks for your suggestions. I’ll look into it. Feel free to pass along the fixes if you’ve implemented them.
this as a view helper for ZF == AWESOME!
@Christian. I agree! That would be the best place for it. I’ll let you know when I get a chance to do just that. Thanks.
Very useful! With ZF i put this as “services”:
class Service_Calendar
and config Bootstrap for the prefix “Service” on a folder into the project, without touch Zend Library.
Hi Derek,
I can’t find class Calendar? Thanks in advance.
Michal
@Michal
You can find it here:
http://code.google.com/p/zfcalendar/source/browse/trunk/Calendar.class.php
Derek,
thanks, now it works but loading pages are really slow.
Do you have the same problem?
Is anything I can do about it?
No. I haven’t experienced slow page loads with this class. Feel free to post (or email) an example of how you’re implementing it.
It’s fine now. I had some problem with my apache server
thanks for help
Hi Derek,
sorry to bother you. I finally implemeted your calendar but I have last issue and can’t solve it.
If I change month through selectbox I get to url ?selectMonth=may+2010. I would like to change it like month/may/year/2010 but I can’t find the place where you set it
Thanks
Michal
@Michal,
You can’t format $_GET parameters passed in a form as ‘month/may/year/2010′. The browser will always pass them as key/value pairs (i.e. ?key1=value1&key2=value2 etc..).
Are you looking to separate the month and year into two separate parameters? i.e. ?month=may&year=2010?
If you don’t want the variables to appear in the URL, change the form method to “post” so that the parameters are passed to the server in the request header.
In either case, you’ll need to check for the request parameters in the controller using $this->_getParam(‘key’, ‘default’) or $this->_getParams() to get them all.
Hi,
I have last question. I would like to have first day of week – monday. Can you help me?
Thanks, Michal
Hi Derek,
thanks a lot. I have last question. I need to have first day of the week monday. I’ve thought it should be set from date_default_timezone = “Europe/Prague” in config.ini
Michal
Hi Michal,
Changing the default_timezone ensures your application is handling dates/times based on your choice of time zones. It won’t change the starting day of the calendar output. Being able to change the week start day would be a nice addition to the Calendar class. Feel like contributing to it? Its done via the $_firstDayOfWeek class variable. The output script would also need to be refactored to accommodate the display of week days etc (see the getCalendarBodyHtml() function).
Derek,
thanks. If I’ll solve it I post the solution
Michal