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.


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',
)); ?>


Vesrion 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 10 comments

#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.

#13561 report it
rajesh chaurasia at 2013/06/06 02:49am

any demo !

Leave a comment

Please to leave your comment.

Create extension