edofre / yii2-fullcalendar
用于 fullcalendar 的 Yii2 小部件
V1.0.11
2018-01-04 21:25 UTC
Requires
- php: >=5.5.0
- npm-asset/fullcalendar: v3.8.0
- yiisoft/yii2: >=2.0.9
- yiisoft/yii2-jui: >=2.0.6
This package is not auto-updated.
Last update: 2024-09-20 21:42:07 UTC
README
安装
安装此扩展的首选方式是通过 composer。
安装方法,运行以下命令之一:
$ php composer.phar require edofre/yii2-fullcalendar "V1.0.11"
或添加
"edofre/yii2-fullcalendar": "V1.0.11"
到您的 composer.json 文件的 require 部分。
用法
Fullcalendar 可以按照以下方式创建,所有选项都是可选的,下面只是大多数选项的一个示例
<?= edofre\fullcalendar\Fullcalendar::widget([ 'options' => [ 'id' => 'calendar', 'language' => 'nl', ], 'clientOptions' => [ 'weekNumbers' => true, 'selectable' => true, 'defaultView' => 'agendaWeek', 'eventResize' => new JsExpression(" function(event, delta, revertFunc, jsEvent, ui, view) { console.log(event); } "), ], 'events' => Url::to(['calendar/events', 'id' => $uniqid]), ]); ?>
事件可以通过三种方式添加,PHP 数组,JavaScript 数组或 JSON 提供程序
PHP 数组
<?php $events = [ new Event([ 'title' => 'Appointment #' . rand(1, 999), 'start' => '2016-03-18T14:00:00', ]), // Everything editable new Event([ 'id' => uniqid(), 'title' => 'Appointment #' . rand(1, 999), 'start' => '2016-03-17T12:30:00', 'end' => '2016-03-17T13:30:00', 'editable' => true, 'startEditable' => true, 'durationEditable' => true, ]), // No overlap new Event([ 'id' => uniqid(), 'title' => 'Appointment #' . rand(1, 999), 'start' => '2016-03-17T15:30:00', 'end' => '2016-03-17T19:30:00', 'overlap' => false, // Overlap is default true 'editable' => true, 'startEditable' => true, 'durationEditable' => true, ]), // Only duration editable new Event([ 'id' => uniqid(), 'title' => 'Appointment #' . rand(1, 999), 'start' => '2016-03-16T11:00:00', 'end' => '2016-03-16T11:30:00', 'startEditable' => false, 'durationEditable' => true, ]), // Only start editable new Event([ 'id' => uniqid(), 'title' => 'Appointment #' . rand(1, 999), 'start' => '2016-03-15T14:00:00', 'end' => '2016-03-15T15:30:00', 'startEditable' => true, 'durationEditable' => false, ]), ]; ?> <?= edofre\fullcalendar\Fullcalendar::widget([ 'events' => $events ]); ?>
JavaScript 数组
<?= edofre\fullcalendar\Fullcalendar::widget([ 'events' => new JsExpression('[ { "id":null, "title":"Appointment #776", "allDay":false, "start":"2016-03-18T14:00:00", "end":null, "url":null, "className":null, "editable":false, "startEditable":false, "durationEditable":false, "rendering":null, "overlap":true, "constraint":null, "source":null, "color":null, "backgroundColor":"grey", "borderColor":"black", "textColor":null }, { "id":"56e74da126014", "title":"Appointment #928", "allDay":false, "start":"2016-03-17T12:30:00", "end":"2016-03-17T13:30:00", "url":null, "className":null, "editable":true, "startEditable":true, "durationEditable":true, "rendering":null, "overlap":true, "constraint":null, "source":null, "color":null, "backgroundColor":"grey", "borderColor":"black", "textColor":null }, { "id":"56e74da126050", "title":"Appointment #197", "allDay":false, "start":"2016-03-17T15:30:00", "end":"2016-03-17T19:30:00", "url":null, "className":null, "editable":true, "startEditable":true, "durationEditable":true, "rendering":null, "overlap":false, "constraint":null, "source":null, "color":null, "backgroundColor":"grey", "borderColor":"black", "textColor":null }, { "id":"56e74da126080", "title":"Appointment #537", "allDay":false, "start":"2016-03-16T11:00:00", "end":"2016-03-16T11:30:00", "url":null, "className":null, "editable":false, "startEditable":false, "durationEditable":true, "rendering":null, "overlap":true, "constraint":null, "source":null, "color":null, "backgroundColor":"grey", "borderColor":"black", "textColor":null }, { "id":"56e74da1260a7", "title":"Appointment #465", "allDay":false, "start":"2016-03-15T14:00:00", "end":"2016-03-15T15:30:00", "url":null, "className":null, "editable":false, "startEditable":true, "durationEditable":false, "rendering":null, "overlap":true, "constraint":null, "source":null, "color":null, "backgroundColor":"grey", "borderColor":"black", "textColor":null }, ]'), ]); ?>
JSON 提供程序
<?= edofre\fullcalendar\Fullcalendar::widget([ 'events' => Url::to(['calendar/events', 'id' => $uniqid]), ]); ?>
然后您的控制器操作将返回如下数组
/** * @param $id * @param $start * @param $end * @return array */ public function actionEvents($id, $start, $end) { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return [ // minimum new Event([ 'title' => 'Appointment #' . rand(1, 999), 'start' => '2016-03-18T14:00:00', ]), // Everything editable new Event([ 'id' => uniqid(), 'title' => 'Appointment #' . rand(1, 999), 'start' => '2016-03-17T12:30:00', 'end' => '2016-03-17T13:30:00', 'editable' => true, 'startEditable' => true, 'durationEditable' => true, ]), // No overlap new Event([ 'id' => uniqid(), 'title' => 'Appointment #' . rand(1, 999), 'start' => '2016-03-17T15:30:00', 'end' => '2016-03-17T19:30:00', 'overlap' => false, // Overlap is default true 'editable' => true, 'startEditable' => true, 'durationEditable' => true, ]), // Only duration editable new Event([ 'id' => uniqid(), 'title' => 'Appointment #' . rand(1, 999), 'start' => '2016-03-16T11:00:00', 'end' => '2016-03-16T11:30:00', 'startEditable' => false, 'durationEditable' => true, ]), // Only start editable new Event([ 'id' => uniqid(), 'title' => 'Appointment #' . rand(1, 999), 'start' => '2016-03-15T14:00:00', 'end' => '2016-03-15T15:30:00', 'startEditable' => true, 'durationEditable' => false, ]), ]; }
回调
回调必须包装在 JsExpression() 对象中。例如,如果您想使用 eventResize,则需要在 fullcalendar 客户端选项中添加以下内容
<?= edofre\fullcalendar\Fullcalendar::widget([ 'clientOptions' => [ 'eventResize' => new JsExpression(" function(event, delta, revertFunc, jsEvent, ui, view) { console.log(event.id); console.log(delta); } "), ], ]); ?>