Yii 1.1: ecalendarview

ECalendarView renders calendar with custom content of day cells.

ECalendarView is Yii extension widget. It renders calendar with custom content of day cells. It is inspired by CListView with two differences:

  • Items are rendered into calendar table instead of list.
  • Item model consists of day's date instead of CModel.


  • Customizable content of day cells.
  • Can be rendered in three pagination modes - month, week and day.
  • Month can be rendered with 1 - 3 weeks in a row.
  • Can be rendered with Monday or Sunday as the first day of week.
  • Custom css and localization possible.
  • Ajax updates.


Tested on Yii 1.1.13.


  • Download and extract to extensions directory.
  • Set path alias in config/main.php.
Yii::setPathOfAlias('ecalendarview', dirname(__FILE__) . '/../extensions/ecalendarview');


Put calendar into view file.

<?php $this->widget('ecalendarview.ECalendarView'); ?>

All attributes are preconfigured to default values. Complete configuration looks like following.

<?php $this->widget('ecalendarview.ECalendarView', array(
  'id' => 'MyCalendar',
  'weeksInRow' => 1,
  'itemView' => '_view',
  'titleView' => '_title',
  'cssFile' => 'css/calendar.css',
  'ajaxUpdate' => true,
  'dataProvider' => array(
    'pagination' => array(
      'currentDate' => new DateTime("now"),
      'pageSize' => 'month',
      'pageIndex' => 0,
      'pageIndexVar' => 'MyCalendar_page',
      'isMondayFirst' => false,
)); ?>
  • id - The identifier of calendar. It must be unique for each calendar rendered on the same view. If not defined, it is auto-generated.
  • weeksInRow - The number of weeks that is be rendered in one row. Valid values are 1 - 3. Has effect only with pageSize set to 'month'.
  • itemView - The view to be used to render each day. If not defined, default view is used. Inside of view following data can be accessed:
    • DateTime $data->date - The date of day.
    • boolean $data->isCurrent - Tells if the day is selected.
    • boolean $data->isRelevant - Tells if the day is not only padding in the beginning and end of the month page.
    • CBaseController $this - The controller.
  • titleView - The view to be used to render month and year information on the top of calendar. If not defined, default view is used. Inside of view following data can be accessed:
    • ECalendarViewPagination $pagination - The pagination of calendar.
  • cssFile - The css file to be used to style calendar. Path is relative to application root. If not defined, default css file is used.
  • ajaxUpdate - Tells if page navigation should be performed using ajax calls if possible. If not defined, true is used.
  • currentDate - The date selected in calendar. If not defined, current date is used.
  • pageSize - Pagination style. Can be set to 'month', 'week' or 'day'. If not defined, 'month' is used.
  • pageIndex - The page index. If not defined, 0 is used. This attribute is overwritten by url request attribute if set.
  • pageIndexVar - The name of url request attribute that holds current page index. If not defined, concatenation of auto-generated id and '_page' is used.
  • isMondayFirst - Tells if Monday is rendered as first day of week, or Sunday. If not defined, false is used.


You can provide message bundle ecalendarview to translate/modify names of days and months. Eg. file <app-root>/protected/messages/en/ecalendarview.php can look like following:

return array(
  'Sun' => 'Sunday',
  'Mon' => 'Hated-day',
  'January' => '1st month',
  'February' => 'Feb',

If you need better control over calendar title ("January, 2014") please have a look on property titleView described above.


Ultimate Weather Forecast is application that can foresee/backsee weather in any time of the future and history. The predictions are highly accurate, but the location for each day forecast is unknown.

1) Create ForecastController with action forecast and view forecast.

2) Add method to controller that do forecast:

public function getForecast($date) {
  $weekdayIndex = $date->format('N') - 1;
  if($weekdayIndex < 5) {
    $temperature = rand(0, 15) . ' °C';
    $conditions = 'rainy';
  } else {
    $temperature = rand(20, 30) . ' °C';
    $conditions = 'sunny';
  return array(
    'temperature' => $temperature,
    'conditions' => $conditions,

3) Define views/forecast/_view.php like following:

<?php if($data->isRelevantDate): ?>
  <?php $forecast = $this->getForecast($data->date); ?>
  <span style="font-size: 60%;"><?php echo $forecast['temperature']; ?></span> <br/>
  <span style="font-size: 60%;"><?php echo $forecast['conditions']; ?></span> <br/>
<? endif; ?>
<?php echo $data->date->format('j'); ?>

4) Render calendar in views/forecast/forecast.php:

<?php $this->widget('ecalendarview.ECalendarView', array(
  'itemView' => '_view',
)); ?>


Version 0.6

  • Fixed behaviour if widget is used in missingAction.

Version 0.5

  • Added attribute ECalendarView::$_titleView.

Version 0.4

  • Fixed "unexpected end of file" when disabled short_open_tag.

Version 0.3

  • Added attribute ECalendarView::$_weeksInRow.
  • Fixed issue with overriden function ECalendarView::getId().

Version 0.2

  • Added attribute ECalendarView::$_id.
  • Added attribute ECalendarView::$_ajaxUpdate.
  • Changed default ECalendarViewPagination::$_pageIndexVar.
  • Controller is accessible in item view by $this.
  • Small visual enhancements.

Version 0.1

  • Initial version.

Other Links

More about my work.

Total 20 comments

#19515 report it
speculatius at 2015/08/13 11:30am
RE: missingAction

Hi Luka,

sorry that it took so long :) Widget works correctly from missingAction now. Please download new version. Thanks for pointing this out.


#19510 report it
Lux69 at 2015/08/11 09:53am

In Yii missingAction($actionID) is a public function that is a part of the CController, when the controller can't find the specified action!

I use the ecalendar in the sidebar, and work correct when is not rendered from the missingAction method.

Try in your ecalendar develop environment define the missingAction in the siteController and then call the URL index.php?r?site/Whatever

Put your calendar in the sidebar and you got the scenario like mine! ;)

I't seems like missingAction method define/call some code that is already defined. But like i told you I didn't done any investigation.

Stack (if you need it) and thanks for your response.:

Time Memory Function Location

1 0.0009 243176 {main}( ) ..\index.php:0 2 0.0481 2201032 CApplication->run( ) ..\index.php:13 3 0.0481 2202120 CWebApplication->processRequest( ) ..\CApplication.php:180 4 0.0505 2389848 CWebApplication->runController( ) ..\CWebApplication.php:141 5 0.0574 2983072 CController->run( ) ..\CWebApplication.php:282 6 0.0575 2983880 SiteController->missingAction( ) ..\CController.php:270 7 0.1811 6364816 CController->render( ) ..\SiteController.php:69 8 0.3072 8464048 CBaseController->renderFile( ) ..\CController.php:784 9 0.3073 8464144 CBaseController->renderInternal( ) ..\CBaseController.php:95 10 0.3078 8500968 require( 'C:\wamp\www\branik\protected\views\layouts\column2.php' ) ..\CBaseController.php:126 11 0.3123 8727520 CBaseController->widget( ) ..\column2.php:56 12 0.3205 8943080 ECalendarView->run( ) ..\CBaseController.php:173 13 0.3391 9013832 ECalendarView->getUrl( ) ..\ECalendarView.php:184 14 0.3391 9014464 CController->createUrl( ) ..\ECalendarView.php:197

#19506 report it
speculatius at 2015/08/09 05:39am
RE: Calling widget throught public function missingAction($actionID) method

Hi Luka,

I will try to help you best I can. But currently I do not understand how you use missingAction method. Did you override it somehow? Could you please send me your controller and respective view? Thank you.


#19505 report it
Lux69 at 2015/08/08 03:09pm
Calling widget throught public function missingAction($actionID) method

I get an fatal error when calling the widget, throught the missingAction function in the SiteController!

Fatal error: Call to a member function getId() on a non-object in C:\wamp\www\yii\framework\web\CController.php on line 962

What's that?! I've tryed to hack, but negative.

Thanks guys! Luka

#19199 report it
speculatius at 2015/04/14 03:18am
PHP 5.2

Based on communication with bighoc, here is the solution for running extension on PHP 5.2...

Problem - DateInterval is not supported in PHP 5.2.

Solution - DateInterval is used only for addition / substraction of some time to given date (see methods http://php.net/manual/en/datetime.add.php and http://php.net/manual/en/datetime.sub.php). This is done in ECalendarViewPagination and once in ECalendarViewDataProvider. You should be able to change those additions / substractions using method modify (http://php.net/manual/en/datetime.modify.php).

#19136 report it
bighoc at 2015/03/27 09:41am
doesn't work on php 5.2

Have any idea how to make it work on php 5.2 ?

#18665 report it
Trejder at 2014/12/09 08:00am
An ehanced version of this extension

I have created an enhanced version of this extension, named yii-calendar.

Beside some cosmetic changes, it includes:

  • some basic, default CSS styling (original extension has no default styling),
  • an ability to pass additional data to make selected days a links to some URLs,
  • fixed path including (no need to add Yii::setPathOfAlias('ecalendarview', ...) in config file.

Feel free to take a look, if you're interested. Have a nice day.

#18659 report it
Trejder at 2014/12/08 08:57am
Custom title view issue

Another thing: where should I keep my custom title view and how should I name it?

I have added 'titleView' => '_title', param to calendar's configuration and I'm getting exception: "require(): Filename cannot be empty". I thought, that maybe this is a "glitch" of using custom view file with default view name, so I changed it to yiiCalendarTitleView (I have a file such file in my app's views), but this doesn't actually change anything.

What am I missing?

#18658 report it
Trejder at 2014/12/08 07:55am
@speculatius: i18n

Nope, man! :] Your solution rocks, and added explanation was all, that I needed. Thanks!

I strongly believe, that translating Yii app the way Yii does (and your calendar right now) is by far better, than using PHP locales. I found many strange PHP locales-related issues during my development experience, but I have not problems using Yii:t. Thanks again, this problem is solved as for me.

#18657 report it
speculatius at 2014/12/08 07:36am
@Trejder: RE:titleView

I see your point. This extension is meant to be localized using message bundle "ecalendarview". I added this information to description above because it was missing. Does it solve your issue, or would you still prefer to use php's built-in mechanism for localisation?

#18656 report it
Trejder at 2014/12/08 05:39am
@speculatius: titleView

I think, you're missing Szigya's comment. Adding titleView property only allows to translate title. And isn't done in a too professional way (rentering entire subview to only change 1-2 words into other language?).

There's still a problem with for example day's names in month view. How to translate Mon (Monday) and others to a different language?

Your extension fails on this, because it uses DateTime::format() (an alias of date_format function), which description clearly says: "This method does not use locales. All output is in English". This causes, that even non-English Yii applications displays your widget in English. Which is wrong.

This should be changed (either by you, in an official release of extension or hand-crafted by anyone needing this) to using PHP's date function, which fully respects language locales in generated date strings.

#16733 report it
speculatius at 2014/03/23 12:08pm

New setting titleView is now available, so that year/month information on the top of calendar can be better customized. This should also solve Szigya's issue with translating that title.

#16354 report it
Szigya at 2014/02/13 05:27pm
Date and time to any language


I started to use your extension on my own language and noticed that DateTime doesn't support other language but english. I've hacked it to my own needs, and it was very nice, but I was not as good guy as I should be, so I can't share it directly via github due to some junk code. I think it would be useful for others too if you could change the datetime->fomat(str) stuff to sg. like this: <?php echo strftime('%A', $data[$i]->getDate()->getTimestamp()); ?> With this improvement we could skip yii translation and display everything "language independent" by setting locale stuff.

Thanks, Mike

ps.: sorry for my english, i was in hurry

#15614 report it
speculatius at 2013/11/28 01:16pm
"unexpected end of file" fixed

"unexpected end of file" issue was fixed in version 0.4 thanks to Gabo.

#15512 report it
speculatius at 2013/11/17 01:25pm
RE: Getting Error

Please check if this is happening even when you remove call to render ecalendarview and remove path alias to ecalendarview in config/main.php. If yes, there could be missing bracket in your code. If no, please send me code of view where you render calendar and let me know your php/yii version.

#15504 report it
swampone at 2013/11/15 08:28pm
Getting Error

im getting this err

Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\webs\next\protected\extensions\ecalendarview\views\month.php on line 66
#15443 report it
Szigya at 2013/11/10 07:57am

Thanks, it works, I just use theme and that was the location where I searched for it, and than in the extension folder, so my fault was that it was not obvious :).

#15442 report it
speculatius at 2013/11/10 07:02am
Re: Css

Thanks for feedback. Css path is relative to application root. So value 'cssFile'=>'css/calendar.css' points to <app-root>/css/calendar.css. Let me know if that does not work for you.

#15441 report it
Szigya at 2013/11/10 05:17am

Nice extension, thanks especially for the monday start parameter :).
Maybe just for me not obvious where the css option points to, but could you please help in it? :)

#13922 report it
tihanyilaci at 2013/07/06 05:41am
Great extension

First i had an error message about ECalendarView::getId() function. But after that i inserted parameter $autoGenerate=true as in the CWidget parent class and it worked.

Leave a comment

Please to leave your comment.

Create extension