我想按类别 json 获取日历事件。
这是我在控制器中的代码
function json_kategori() {
header("Content-Type: application/json");
echo $this->MKalender->jsonEventsByKategori();
}
这是我在模型中的代码
function jsonEventsByKategori($catid) {
$this->db->order_by('TanggalMulai', 'desc');
$this->db->where("IDKategori", $catid);
$events = $this->db->get('kalender')->result();
$jsonevents = array();
foreach ($events as $entry) {
$jsonevents[] = array(
'id' => $entry->IDKalender,
'start' => $entry->TanggalMulai,
'end' => $entry->TanggalAkhir,
'title' => $entry->judul,
'body' => $entry->konten,
'multi' => 0,
'allDay' => false,
'extension_id' => 2
);
}
return json_encode($jsonevents);
}
这是我在视图中的代码 [加载 json 日历事件]
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$('#calendar').fullCalendar({
firstDay:'1',
theme:true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
events: '<?= base_url(); ?>kalender/json_kategori'
});
});
数据库表名是 kalender 和 kalender_kategori
我的日历 SQL 是
CREATE TABLE `kalender`(
`IDKalender` INT(10)UNSIGNED NOT NULL AUTO_INCREMENT,
`IDKategori` INT(11)NOT NULL,
`TanggalMulai` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`TanggalAkhir` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`judul` VARCHAR(100)NOT NULL,
`konten` text NOT NULL,
`user` VARCHAR(25)NOT NULL DEFAULT 'anonimous',
PRIMARY KEY(`IDKalender`))ENGINE = MyISAM AUTO_INCREMENT = 3 DEFAULT CHARSET = latin1;
我的 kalender_kategory SQL 是
CREATE TABLE `kalender_kategori`(
`IDKategori` TINYINT(11)NOT NULL AUTO_INCREMENT,
`kategori` VARCHAR(60)COLLATE latin1_general_ci NOT NULL DEFAULT '',
`deskripsi` text COLLATE latin1_general_ci NOT NULL,
PRIMARY KEY(`IDKategori`))ENGINE = MyISAM AUTO_INCREMENT = 9 DEFAULT CHARSET = latin1 COLLATE = latin1_general_ci;
如果上面的代码是错误的?如果有的话,哪一部分是错的?如果我想甚至只存在于特定事件类别中。