solution10/calendar

简单但强大的日历,适用于任何模板系统

v1.3.0 2017-06-06 14:57 UTC

This package is not auto-updated.

Last update: 2024-09-14 15:42:33 UTC


README

日历组件是一个简单但功能强大的包,可以帮助您渲染日历!

Build Status Latest Stable Version Total Downloads License

特点

  • 无依赖项
  • PHP 5.3+
  • 直观的接口
  • 支持多种“分辨率”(周视图、月视图等)
  • 易于扩展
  • 模板系统无关

入门指南

安装通过composer进行,遵循常规方式

{
    "require": {
        "solution10/calendar": "^1.0"
    }
}

创建基本日历的方法如下

<?php
// Creates a calendar, using today as a starting point.
$calendar = new Solution10\Calendar\Calendar(new DateTime('now'));

// We now need to give the calendar a "resolution". This tells the
// Calendar whether we're showing a month view, or a Week, or maybe
// even a whole year. Let's start with a Month:

$calendar->setResolution(new MonthResolution());

// That's it! Let's grab the view data and render:
$viewData = $calendar->viewData();
$months = $viewData['contents'];
?>

<?php foreach ($months as $month): ?>
<table>
    <caption><?php echo $month->title('F Y'); ?></caption>
    <thead>
        <tr>
            <?php foreach ($month->weeks()[0]->days() as $day): ?>
                <th><?php echo $day->date()->format('D'); ?></th>
            <?php endforeach; ?>
        </tr>
    </thead>
    <tbody>
        <?php foreach ($month->weeks() as $week): ?>
            <tr>
                <?php foreach ($week->days() as $day): ?>
                    <td>
                        <?php
                            if ($day->isOverflow()) {
                                if ($calendar->resolution()->showOverflowDays()) {
                                    echo '<span style="color: #ccc">'.$day->date()->format('d').'</span>';
                                } else {
                                    echo '&nbsp;';
                                }
                            } else {
                                echo $day->date()->format('d');
                            }
                        ?>
                    </td>
                <?php endforeach; ?>
            </tr>
        <?php endforeach; ?>
    </tbody>
</table>
<?php endforeach; ?>

Solution10\Calendar不提供模板,因为我们不知道您使用的是哪种模板引擎(如果有的话)。相反,我们为您提供强大而简单的API,以便您可以自行进行渲染。

进一步阅读

用户指南

有关创建日历的更多信息,请参阅日历部分

如果您想了解更多关于分辨率的信息,请查看分辨率部分

想要了解如何将事件添加到日历中?请查看事件部分

PHP需求

  • PHP >= 5.3

作者

Alex Gisby: GitHub, Twitter

许可

MIT

贡献

贡献者说明