我有一个问题,我是php telerik的新手,它是用于保存,删除和更新的调度程序,但这不是第一次显示数据,我使用的是Mysql。 我正在使用官方网站http://demos.telerik.com/php-ui/scheduler/resources
中的示例感谢您的帮助
<?php
require_once '../lib/DataSourceResult.php';
require_once '../lib/SchedulerDataSourceResult.php';
require_once '../lib/Kendo/Autoload.php';
$columns = array('MeetingID', 'Title', 'Start', 'End', 'StartTimezone', 'EndTimezone', 'IsAllDay', 'Description', 'RecurrenceID', 'RecurrenceRule', 'RecurrenceException', 'RoomID');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
header('Content-Type: application/json');
$request = json_decode(file_get_contents('php://input'));
//$result = new SchedulerDataSourceResult('sqlite:..//sample.db');
$result = new SchedulerDataSourceResult('mysql:host=localhost;dbname=test', 'root', 'password');
$type = $_GET['type'];
switch($type) {
case 'create':
$result = $result->createWithAssociation('Meetings', 'MeetingAttendees', $columns, $request->models, 'MeetingID', array('Attendees' => 'AttendeeID'));
break;
case 'update':
$result = $result->updateWithAssociation('Meetings', 'MeetingAttendees', $columns, $request->models, 'MeetingID', array('Attendees' => 'AttendeeID'));
break;
case 'destroy':
$result = $result->destroyWithAssociation('Meetings', 'MeetingAttendees', $request->models, 'MeetingID');
break;
default:
$result = $result->readWithAssociation('Meetings', 'MeetingAttendees', 'MeetingID', array('AttendeeID' => 'Attendees'), array('MeetingID', 'RoomID'), $request);
break;
}
echo json_encode($result, JSON_NUMERIC_CHECK);
exit;
}
require_once '../include/header.php';
$transport = new \Kendo\Data\DataSourceTransport();
$create = new \Kendo\Data\DataSourceTransportCreate();
$create->url('resources.php?type=create')
->contentType('application/json')
->type('POST');
$read = new \Kendo\Data\DataSourceTransportRead();
$read->url('resources.php?type=read')
->contentType('application/json')
->type('POST');
$update = new \Kendo\Data\DataSourceTransportUpdate();
$update->url('resources.php?type=update')
->contentType('application/json')
->type('POST');
$destroy = new \Kendo\Data\DataSourceTransportDestroy();
$destroy->url('resources.php?type=destroy')
->contentType('application/json')
->type('POST');
$transport->create($create)
->read($read)
->update($update)
->destroy($destroy)
->parameterMap('function(data) {
return kendo.stringify(data);
}');
$model = new \Kendo\Data\DataSourceSchemaModel();
$meetingIdField = new \Kendo\Data\DataSourceSchemaModelField('meetingID');
$meetingIdField->type('number')
->from('MeetingID')
->nullable(true);
$titleField = new \Kendo\Data\DataSourceSchemaModelField('title');
$titleField->from('Title')
->defaultValue('No title')
->validation(array('required' => true));
$startField = new \Kendo\Data\DataSourceSchemaModelField('start');
$startField->type('date')
->from('Start');
$startTimezoneField = new \Kendo\Data\DataSourceSchemaModelField('startTimezone');
$startTimezoneField->from('StartTimezone');
$endField = new \Kendo\Data\DataSourceSchemaModelField('end');
$endField->type('date')
->from('End');
$endTimezoneField = new \Kendo\Data\DataSourceSchemaModelField('endTimezone');
$endTimezoneField->from('EndTimezone');
$isAllDayField = new \Kendo\Data\DataSourceSchemaModelField('isAllDay');
$isAllDayField->type('boolean')
->from('IsAllDay');
$descriptionField = new \Kendo\Data\DataSourceSchemaModelField('description');
$descriptionField->type('string')
->from('Description');
$recurrenceIdField = new \Kendo\Data\DataSourceSchemaModelField('recurrenceId');
$recurrenceIdField->from('RecurrenceID');
$recurrenceRuleField = new \Kendo\Data\DataSourceSchemaModelField('recurrenceRule');
$recurrenceRuleField->from('RecurrenceRule');
$recurrenceExceptionField = new \Kendo\Data\DataSourceSchemaModelField('recurrenceException');
$recurrenceExceptionField->from('RecurrenceException');
$roomIdField = new \Kendo\Data\DataSourceSchemaModelField('roomId');
$roomIdField->from('RoomID')
->nullable(true);
$attendeesField = new \Kendo\Data\DataSourceSchemaModelField('attendees');
$attendeesField->from('Attendees')
->defaultValue([]);
$model->id('meetingID')
->addField($meetingIdField)
->addField($titleField)
->addField($startField)
->addField($endField)
->addField($startTimezoneField)
->addField($endTimezoneField)
->addField($descriptionField)
->addField($recurrenceIdField)
->addField($recurrenceRuleField)
->addField($recurrenceExceptionField)
->addField($roomIdField)
->addField($attendeesField)
->addField($isAllDayField);
$schema = new \Kendo\Data\DataSourceSchema();
$schema->data('data')
->errors('errors')
->model($model);
$dataSource = new \Kendo\Data\DataSource();
$dataSource->transport($transport)
->schema($schema)
->batch(true);
$roomResource = new \Kendo\UI\SchedulerResource();
$roomResource->field('roomId')
->title('Room')
->dataSource(array(
array('text'=> 'Meeting Room 101', 'value' => 1, 'color' => '#6eb3fa'),
array('text'=> 'Meeting Room 201', 'value' => 2, 'color' => '#f58a8a')
));
$attendeesResource = new \Kendo\UI\SchedulerResource();
$attendeesResource->field('attendees')
->title('Attendees')
->multiple(true)
->dataSource(array(
array('text'=> 'Alex', 'value' => 1, 'color' => '#f8a398'),
array('text'=> 'Bob', 'value' => 2, 'color' => '#51a0ed'),
array('text'=> 'Charlie', 'value' => 3, 'color' => '#56ca85')
));
$scheduler = new \Kendo\UI\Scheduler('scheduler');
$scheduler->timezone("Etc/UTC")
->date(new DateTime('2013/6/13'))
->height(600)
->addResource($roomResource, $attendeesResource)
->addView(array('type' => 'day', 'startTime' => new DateTime('2013/6/13 7:00')),
array('type' => 'week', 'selected' => true, 'startTime' => new DateTime('2013/6/13 7:00')), 'month', 'agenda', 'timeline')
->dataSource($dataSource);
echo $scheduler->render();
?>
<?php require_once '../include/footer.php'; ?>