ecalendarview ECalendarView renders calendar with custom content of day cells.

  1. Features
  2. Requirements
  3. Installation
  4. Usage
  5. i18n
  6. Example
  7. Changelog
  8. Other Links

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

  • Code moved to github with minimal cleanup changes.

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.

5 0
2 510 downloads
Yii Version: 1.1.*
License: MIT
Category: Date and Time
Tags: calendar
Developed by: speculatius
Created on: Jun 4, 2013
Last updated: 5 years ago
Github Repository


show all

Related Extensions