tito10047/php-callendar 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tito10047/php-callendar

最新稳定版本:1.0.0

Composer 安装命令:

composer require tito10047/php-callendar

包简介

Php server side rendered calendar

README 文档

README

PHP Tests

Plain PHP Calendar Package

This package provides a simple calendar component that can be used in PHP applications.

Installation

To install the package, use the following commands:

Using Composer

composer require tito10047/php-callendar

Usage

In PHP

To use the calendar component in your PHP application, include the autoload file and instantiate the calendar class.

require 'vendor/autoload.php';

use Tito10047\Calendar\Calendar;
use Tito10047\Calendar\Enum\CalendarType;
use Tito10047\Calendar\Enum\DayName;

$calendar = new Calendar(
    date:new DateTime('2021-01-01'),
    daysGenerator:CalendarType::Monthly,
    startDay:DayName::Monday
);
$nextMonthCalendar = $calendar->nextMonth();
$renderer = Renderer::factory(CalendarType::Monthly,'calendar');

$calendar->disableDays(new DateTime('2021-01-01'));
$calendar->disableDaysByName(DayName::Sunday);
$nextMonthCalendar->disableDaysByName(DayName::Sunday);

echo $renderer->render($calendar);
echo $renderer->render($nextMonthCalendar);

In Twig

To use the calendar component in your Twig template, include the calendar template and pass the calendar object to the template.

use Tito10047\Calendar\Calendar;
$calendar = new Calendar(
    date:new DateTime('2021-01-01'),
    daysGenerator:CalendarType::Monthly,
    startDay:DayName::Monday
);
$table = $calendar->getDaysTable();
<table>
{%for weekNum,week in table%}
    <tr>
        {%for dayNum,day in week%}
            {% set classes = 'day' %}
            {% if day.today %}{% set classes = classes ~ ' today' %}{% endif %}
            {% if not day.enabled %}{% set classes = classes ~ ' disabled' %}{% endif %}
            <td>
                {% if not day.ghost %}
                    {{day.date|format('d')}}
                {%endif%}                    
            </td>
        {%endfor%}
    </tr>
{%endfor%}
</table>

Custom Days Generator

You can create your own days generator by implementing the DaysGeneratorInterface interface.

use Tito10047\Calendar\Interface\DaysGeneratorInterface;

class CustomDaysGenerator implements DaysGeneratorInterface
{
    public function getDays(\DateTimeImmutable $day, DayName $firstDay):array
    {
        // Your custom logic here
    }
}

$calendar = new Calendar(
    date:new DateTime('2021-01-01'),
    daysGenerator:new CustomDaysGenerator(),
    startDay:DayName::Monday
);

统计信息

  • 总下载量: 72
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2025-03-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固