PHPackages                             nedarta/yii2-calendar-widget - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. nedarta/yii2-calendar-widget

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

nedarta/yii2-calendar-widget
============================

A premium, modern, and AJAX-powered calendar widget for Yii2 Framework and Bootstrap 5.

v1.1.0(3mo ago)017MITPHP

Since Feb 10Pushed 2mo agoCompare

[ Source](https://github.com/nedarta/yii2-calendar-widget)[ Packagist](https://packagist.org/packages/nedarta/yii2-calendar-widget)[ RSS](/packages/nedarta-yii2-calendar-widget/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (3)Used By (0)

Yii2 Calendar Widget
====================

[](#yii2-calendar-widget)

A premium, modern, and AJAX-powered calendar widget for Yii2 Framework and Bootstrap 5.

[![Calendar Widget Preview](https://raw.githubusercontent.com/nedarta/yii2-calendar-widget/main/screenshots/preview.png)](https://raw.githubusercontent.com/nedarta/yii2-calendar-widget/main/screenshots/preview.png)

Features
--------

[](#features)

- **ActiveRecord Integration**: Easily bind the widget to any `ActiveQuery`.
- **AJAX-Powered**: Month switching and day selection use `Pjax` for a seamless experience.
- **Localization (Intl)**: Automatic translation of month and day names using PHP's `intl` extension.
- **Dynamic Day Names**: Choose between narrow, short, abbreviated, or full day names.
- **Custom Event Rendering**: Pass a closure to fully customize how events appear in the sidebar.
- **Custom Celebrations**: Highlight holidays or special dates with custom styling.
- **Bootstrap 5**: Native support for Bootstrap 5 layout and styling.
- **Rich Interaction**: Days with events are highlighted with a status dot.
- **Flexible Attributes**: Supports dot-notation for relations (e.g., `event.name`) and single `datetime` columns.
- **Mobile Responsive**: Adaptive layout for smaller screens.

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist nedarta/yii2-calendar-widget "*"
```

or add

```
"nedarta/yii2-calendar-widget": "*"
```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

### Simple Usage

[](#simple-usage)

If you have an `Event` model with separate `date` and `time` columns:

```
use nedarta\calendar\CalendarWidget;
use app\models\Event;

echo CalendarWidget::widget([
    'query' => Event::find(),
    'dateAttribute' => 'event_date', // e.g., '2023-07-04'
    'titleAttribute' => 'name',
    'timeAttribute' => 'start_time', // e.g., '09:00'
]);
```

### Handling Relationships

[](#handling-relationships)

For a one-to-many relationship (like `EventTimes` related to an `Event`):

```
use nedarta\calendar\CalendarWidget;
use app\models\EventTime;

echo CalendarWidget::widget([
    'query' => EventTime::find()->joinWith('event'),
    'dateAttribute' => 'date',
    'timeAttribute' => 'time',
    'titleAttribute' => 'event.name', // Access relation attributes with dot-notation
]);
```

### Using a Single Datetime Column

[](#using-a-single-datetime-column)

If your table stores both date and time in a single column (like `datetime` or `timestamp`):

```
echo CalendarWidget::widget([
    'query' => MovieShowtime::find(),
    'dateAttribute' => 'start_at', // '2023-07-04 14:00:00'
    'timeAttribute' => 'start_at', // Extracts '14:00' automatically
    'titleAttribute' => 'movie_name',
]);
```

### Customizing Navigation URLs

[](#customizing-navigation-urls)

By default, the widget uses the current page URL for navigation. You can customize the URLs:

```
echo CalendarWidget::widget([
    'query' => Event::find(),
    'navUrl' => '/events/calendar', // URL for month navigation
    'viewUrl' => '/events/view',    // URL for day selection
]);
```

### Localization &amp; Internationalization

[](#localization--internationalization)

The widget uses PHP's `intl` extension to automatically localize month and day names. You can specify the language and the format of day names:

```
echo CalendarWidget::widget([
    'query' => Event::find(),
    'language' => 'lv-LV',      // language code
    'dayNameFormat' => 'short',  // 'narrow', 'short', 'abbr', or 'full'
    'firstDayOfWeek' => 1,       // 0 = Sunday, 1 = Monday, etc.
]);
```

#### Supported Day Name Formats:

[](#supported-day-name-formats)

- `narrow`: Single letter (e.g., 'P')
- `short`: Two letters (e.g., 'Pr')
- `abbr`: Abbreviated (e.g., 'Pirmd.') - **Default**
- `full`: Full name (e.g., 'Pirmdiena')

### Marking Celebration Days

[](#marking-celebration-days)

You can highlight specific dates (e.g., holidays, birthdays) using the `celebrations` array. It supports both fixed dates (`Y-m-d`) and recurring dates (`m-d`):

```
echo CalendarWidget::widget([
    'query' => Event::find(),
    'celebrations' => [
        '2025-01-01', // Fixed date
        '05-04',      // Recurring yearly (May 4th)
        '11-18',      // Recurring yearly (Nov 18th)
    ],
]);
```

### Custom HTML Attributes

[](#custom-html-attributes)

Add custom CSS classes or HTML attributes to the container:

```
echo CalendarWidget::widget([
    'query' => Event::find(),
    'options' => [
        'class' => 'my-custom-calendar',
        'data-theme' => 'dark',
    ],
]);
```

### Custom Event Rendering

[](#custom-event-rendering)

You can fully customize the HTML output of each event in the sidebar by providing the `eventRender` callback:

```
echo CalendarWidget::widget([
    'query' => Event::find(),
    'eventRender' => function($model, $calendar) {
        return '

                    ' . Html::encode($model->title) . '
                    ' . $model->start_time . '

        ';
    },
]);
```

Styling
-------

[](#styling)

The widget uses standard Bootstrap 5 classes and includes a custom CSS file with specific classes for Saturdays, Sundays, and celebrations:

- `.saturday`: Applied to Saturday cells (default: blue text).
- `.sunday`: Applied to Sunday cells (default: red text).
- `.celebration`: Applied to cells defined in the `celebrations` array.

To override styles, you can point to your own CSS in your application's asset bundle or use the widget within a themed container.

Testing
-------

[](#testing)

This package includes a comprehensive PHPUnit test suite with 29 test cases covering all major functionality.

### Running Tests

[](#running-tests)

Install development dependencies:

```
composer install
```

Run the test suite:

```
composer test
# or
vendor/bin/phpunit
```

### Test Coverage

[](#test-coverage)

The test suite includes:

- Widget initialization and configuration
- Calendar day generation (including leap years)
- Event retrieval and formatting
- Navigation URL handling
- **Localization (Intl)**
- **Day name format options**
- **Custom event rendering callback**
- **Celebration day markers**
- **Weekend flag detection**
- Custom attribute support
- Edge cases and boundary conditions

All tests are passing with 120+ assertions ensuring reliable functionality.

License
-------

[](#license)

This project is licensed under the MIT License.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance83

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

92d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5b419e3f062d93e558b33278c937dacbb5367edf84b8d8b134ba1d86d56f185b?d=identicon)[nedarta](/maintainers/nedarta)

---

Top Contributors

[![nedarta](https://avatars.githubusercontent.com/u/16962105?v=4)](https://github.com/nedarta "nedarta (22 commits)")

---

Tags

yii2extensionajaxcalendarwidgetbootstrap5

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nedarta-yii2-calendar-widget/health.svg)

```
[![Health](https://phpackages.com/badges/nedarta-yii2-calendar-widget/health.svg)](https://phpackages.com/packages/nedarta-yii2-calendar-widget)
```

###  Alternatives

[richardfan1126/yii2-js-register

Yii2 widget to register JS into view

1357.2k7](/packages/richardfan1126-yii2-js-register)[kriss/yii2-calendar-schedule

Yii2 Calendar Schedule

107.9k](/packages/kriss-yii2-calendar-schedule)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
